json-parse-language

1.0.3 • Public • Published

JSON Parse Language

For parsing the complex json in a simple way by specing it.

Guide

const transformObject = require(".");
transformObject(data,spec)

For accessing a key you can put @ For example

{
    name: "@profile.name"
}

For concatenating

{
    name: "@profile.name + @profile.address"
}
{
    name: "@profile.name + 'is good'"
}

For array operations

{
    name: "@profile.marks[*].mark"
}

Example

const complexJSON={
    name: "Govind",
    progressCard: {
        marks: [{
            subject: "Mathematics",
            mark: 49,
            outOf: 50
        },
        {
            subject: "Physics",
            mark: 40,
            outOf: 50
        },],
        age: 29
    }
}

const specJSON = {
    name: "@name",
    totalMarksReceived:"@progressCard.marks[*].mark",
    totalMarks:"@progressCard.marks[*].outOf",
    note: "@name+' is good at mathematics'"
}

// Output Will be 
{
    name: "Govind",
    totalMarksReceived: 89,
    totalMarks: 100,
    note: "Govind is good at mathematics"
}

Readme

Keywords

Package Sidebar

Install

npm i json-parse-language

Weekly Downloads

1

Version

1.0.3

License

ISC

Unpacked Size

6.56 kB

Total Files

5

Last publish

Collaborators

  • govi757