Library to take and apply JSONata transformations to any incoming JSON
npm install mapping-lib-cg-lib
npm install jsonata-mapping-cg-lib, npm i jsonata-mapping-cg-lib or yarn install jsonata-mapping-cg-lib
[
{
"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_
$3
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:
`json
{
"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.
`json
{
"jsonata_expression": "{\"name\": FirstName & \" \" & Surname,\"mobile\": Phone[type = \"mobile\"].number}"
}
`
The teting payload need to be on JSON format.
`json
{
"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.
`json
{
"name": "Fred Smith",
"mobile": "077 7700 1234"
}
``