šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

json-partial

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-partial

Parses a json file looking for partials. If found the partial is read and applied to the json file. On exit saves the json with the provided output name.

1.0.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

json-partial

This module will allow to use json "partials" and expand them into another json file. Sometimes you have one or more json snippets and you may want to use them to build a bigger json file. One example is when you are using json to generate templates with handlebars or mustache.

Installation

npm install json-partial

Usage

Suppose you have a JSON snippet that is repeated almost without change in several places of a large JSON file.

{
    "charRemaining": "50",
    "counterText": "characters remaining",
    "fieldName": "customerName",
    "fieldSize": "large",
    "labelPosition": "",
    "labelText": "Customer Name",
    "maxLength": "50",
    "placeHolder": "Enter customer name",
    "value": ""
}

You want to use almost the same values in two places:

{
    "userName": {
        "charRemaining": "50",
        "counterText": "characters remaining",
        "fieldName": "userName",
        "fieldSize": "large",
        "labelPosition": "",
        "labelText": "User Name",
        "maxLength": "50",
        "placeHolder": "enter user name",
        "value": ""
    },
    "password": {
        "charRemaining": "50",
        "counterText": "characters remaining",
        "fieldName": "password",
        "fieldSize": "large",
        "labelPosition": "",
        "labelText": "Password",
        "maxLength": "50",
        "placeHolder": "enter password",
        "value": "",
        "inputType": "password"
    }
}

With json-partial you can rewrite the file like this:

{
    "jsonx": [
        {
            "file": "bar.json",
            "field": "userName",
            "data": {
                "fieldName": "userName",
                "labelText": "User Name",
                "placeHolder": "enter user name"
            }
        },
        {
            "file": "bar.json",
            "field": "password",
            "data": {
                "fieldName": "password",
                "labelText": "Password",
                "placeHolder": "enter password",
                "inputType": "password"
            }
        }
    ]
}

You will have several advantages:

  • The file is cleaner and only the data that changes is required
  • You will need to modify only one instance of the snippet in case of a change or bugs

Keywords

JSON

FAQs

Package last updated on 19 Apr 2017

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