npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mapping-lib-cg-lib

v1.0.7

Published

Library to take and apply JSONata transformations to any incoming JSON

Downloads

8

Readme

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": [
        "[email protected]",
        "[email protected]"
      ]
    },
    {
      "type": "home",
      "address": [
        "[email protected]",
        "[email protected]"
      ]
    }
  ],
  "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"
}