New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

jf-json-parse

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

jf-json-parse

Parse a JSON file replacing all files included with their contents.

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
5
400%
Maintainers
1
Weekly downloads
 
Created
Source

jf-json-parse stable

npm install jf-json-parse

Parse a JSON file replacing all files included with their contents. If a file does not exist the text is not replaced.

Example

// a.json
{
    "a1" : "Texto del archivo A",
    "a2" : "archivo a.json"
}
// b.json
{
    "b1" : "Archivo B",
    "b2" : "./a.json"
}
// index.json
{
    "a" : "a.json",
    "b" : "./b.json",
    "c" : "Clave c",
    "d" : "d.json",
    "e" : "/tmp/e.json"
}
const jfJsonParse = require('jf-json-parse');

console.log(
    jfJsonParse('./index.json'),
    {
        '/tmp/e.json' : '"fake content"'
    }
);
/*
{
    "a": {
        "a1": "Texto del archivo A",
        "a2": "archivo a.json"
    },
    "b": {
        "b1": "Archivo B",
        "b2": {
            "a1": "Texto del archivo A",
            "a2": "archivo a.json"
        }
    },
    "c": "Clave c",
    "d": "d.json",
    "e": "fake content"
}
*/

Cache

You can pass an object as second parameter as cache. If the key exists in cache, this value will be used instead file on disk.

After parse JSON, in cache object you will have all the files that were tried to read. So you can pass the same cache object between calls to jfJsonParse and no files will be read twice.

const jfJsonParse = require('jf-json-parse');
const cache       = {};

jfJsonParse('./index.json', cache);

// There is no file readings because for this JSON all files are in cache.
jfJsonParse('./index.json', cache);

// For this JSON only will read x.json because there is not in cache.
// z.json: { "a": "a.json", x: "x.json" }
jfJsonParse('./z.json', cache);

Keywords

import

FAQs

Package last updated on 02 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