🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

json-to-json-mapper

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-to-json-mapper

Map Json to Json, using enum to cast object when converting id to string

1.1.2
latest
Source
npm
Version published
Weekly downloads
50
525%
Maintainers
1
Weekly downloads
 
Created
Source

Node.js Package

JSON Auto-mapper

How to use?

use the function map(jsonObject, mappingsDefinition, saveToFile);

  • jsonObject: is your json file parsed to json object
  • mappingsDefinition: is a list of mappings, see below
  • saveToFile: true/false if you want to save the resolts to a file

Exemple 1

//input
{
    request: {
        order:{
            id: "1"
        }
    }
}

//map
{
    source: "request.order.id",
    target: "app.ordering.number",
}

//output
{
    app: {
        ordering:{
            number: 1
        }
    }
}

Exemple 2

//input
{
    request: {
        order:[{
            id: "1"
        }]
    }
}

//map
{
    source: "request.order.id",
    target: "app.ordering.number",
    format: Number,
    take: 1
}

//output
{
    app: {
        ordering:{
            number: 1
        }
    }
}

Exemple 3

//input
{
    request: {
        order:[{
            id: "1",
            code: "2"
        }]
    }
}

//map
Enum EnumObject{
    A = 1,
    B = 2
}

{
    source: "request.order.code",
    target: "app.ordering.text",
    enum: EnumObject,
}

//output
{
    app: {
        ordering:{
            text: "A"
        }
    }
}

Exemple 4

//input
{
    request: {
        order:[{
            id: "1",
            code: "2"
        }]
    }
}

//map
{
    source: "request.order.id",
    target: "app.ordering.$.number.id",
    format: Number,
}

//output
{
    app: {
        ordering: [
            {
                number: {
                    id: 1,
                },
            },
        ],
    },
}

FAQs

Package last updated on 27 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts