ut-jsonpath

1.0.1 • Public • Published

ut-jsonpath

This module provides all the functionality that jsonpath provides.

Additional Methods

jp.transform(obj, template)

Template based json-to-json transformation.

 
const jp = require('ut-jsonpath');
 
const data = {
    name: 'Bulgaria',
    population: 7101859,
    cities: [
        {
            name: 'Sofia',
            'population': 1547472
        },
        {
            name: 'Plovdiv',
            'population': 544628
        }
    ]
};
 
const template = {
    countryName: '$.name',
    population: '$.population',
    cities: ['$.cities', {
        cityName: '$.name'
    }]
};
 
const transformed = jp.transform(data, template);
 
/*
    {
        countryName: 'Bulgaria',
        population: 7101859,
        cities: [
            {
                cityName: 'Sofia'
            },
            {
                cityName: 'Plovdiv'
            }
        ]
    }
*/

Values are also composable. I.e. Multiple selectors can be specified. e.g: '$.name $.population' The necessary interpolations will be applied as long as the selectors are jsonpath compliant.

Package Sidebar

Install

npm i ut-jsonpath

Weekly Downloads

3

Version

1.0.1

License

Apache-2.0

Unpacked Size

17.2 kB

Total Files

7

Last publish

Collaborators

  • kalin.krustev