1.0.6 • Published 1 month ago

mapping-lib-cg-lib v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
1 month ago

N|Solid

jsonata-mapping-cg-lib

1. Introduction

This library has the purpose of apply JSONata query/transform expressions to any incoming JSON, weather is on base64 or as JSON.

This library could be used as part of a component based on Open Integration Hub (OIH) framework or any Nodejs development that requires applying JSONata query search or transformation.

The library can be installed from npm page with the next:

npm install jsonata-mapping-cg-lib, npm i jsonata-mapping-cg-lib or yarn install jsonata-mapping-cg-lib

Within "jsonata-mapping-cg-lib" two additional libraries are used: jsonata: This is the main library used for JSONata query/transform application. utils-nxg-cg: is a N3xGen library that is used to print the necessary logs and help with different functions to validate the payload.

The final result of the process will be the transformation or the query result from the established JSONata expression at the start of the application or flow in OIH, this data will be returned as JSON format:

[
  {
    "customer": "Joe Doe",
    "book": "Structure and Interpretation of Computer Programs",
    "due": "2016-12-05"
  },
  {
    "customer": "Jason Arthur",
    "book": "Compilers: Principles, Techniques, and Tools",
    "due": "2016-10-22"
  },
  {
    "customer": "Jason Arthur",
    "book": "Structure and Interpretation of Computer Programs",
    "due": "2016-12-22"
  }
]

It is important to mention that before the method returns the information, it will be validated that the response if it is a valid JSON or valid JSON Array. If this is correct, the response will be returned, otherwise an exception will be thrown and the flow or process will stop. It is important to mention that for jsonata_expression property is importan to send it as JSON format otherwise it will return error.

2. Methods explanation

2.1. transformCsvToJson

This method is used to apply query search or transformations to any incoming payload. By default there is no "jsonta_expressions" established. It is neccesary to send a jsonata expression.

3. Argument and result explanation

  • Args:

    • In the applyJSONata method there is only one parameter necessary:
      • jsonata_expression: This one parameter will be the query expression that is going to be applied to all incoming JSON, this parameter need to be passed as JSON format since it will be validated before.
      • content(required): This parameter is the content that will be transformed or search on it, it could be on JSON format or base64.
  • Result: The final result will variate depending on the jsonata_expression is established at the start moment. And the incoming JSON as a payload. If the jsonata expression is the following:

{
  "name": FirstName & " " & Surname,
  "mobile": Phone[type = "mobile"].number
}

3. Examples

This part explains some examples of how to send the input parameters to the library and what the result would be. The following data could be a valid jsonata expression to use as to evaaluate some JSON payload.

The JSONata expression and JSON payload could be in base64 encode or plain JSON.

{
    "jsonata_expression": "{\"name\": FirstName & \" \" & Surname,\"mobile\": Phone[type = \"mobile\"].number}"
}

The teting payload need to be on JSON format.

{
  "FirstName": "Fred",
  "Surname": "Smith",
  "Age": 28,
  "Address": {
    "Street": "Hursley Park",
    "City": "Winchester",
    "Postcode": "SO21 2JN"
  },
  "Phone": [
    {
      "type": "home",
      "number": "0203 544 1234"
    },
    {
      "type": "office",
      "number": "01962 001234"
    },
    {
      "type": "office",
      "number": "01962 001235"
    },
    {
      "type": "mobile",
      "number": "077 7700 1234"
    }
  ],
  "Email": [
    {
      "type": "office",
      "address": [
        "fred.smith@my-work.com",
        "fsmith@my-work.com"
      ]
    },
    {
      "type": "home",
      "address": [
        "freddy@my-social.com",
        "frederic.smith@very-serious.com"
      ]
    }
  ],
  "Other": {
    "Over 18 ?": true,
    "Misc": null,
    "Alternative.Address": {
      "Street": "Brick Lane",
      "City": "London",
      "Postcode": "E1 6RF"
    }
  }
}

And the following is the final result for the transform / query.

{
  "name": "Fred Smith",
  "mobile": "077 7700 1234"
}

1.0.6

1 month ago

1.0.5

6 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.4

6 months ago

1.0.3

7 months ago

1.0.0

9 months ago

0.1.13

9 months ago

0.1.12

9 months ago

0.1.11

9 months ago

0.1.10

9 months ago

0.1.9

9 months ago

0.1.8

9 months ago

0.1.7

9 months ago

0.1.6

9 months ago

0.1.5

9 months ago

0.1.4

9 months ago

0.1.3

9 months ago

0.1.2

10 months ago

0.1.1

11 months ago

0.1.0

11 months ago

0.0.9

11 months ago

0.0.8

11 months ago