0.0.4 • Published 2 years ago

json-fields-extractor v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

JSON fields extractor

npm version install size npm downloads Known Vulnerabilities

Can extract fields / schema from JSON object or JSON string.

usage

extractJSON(data, options)

data is a JSON object or string

options is an optional object:

  • options.extract_mode
    • type(default) extract type of value, there are six types. See JSON Data Types
    • value extract value
  • options.skip_keys_sort(default false) skip sorting of result keys
  • options.skip_values_sort(default false) skip sorting of result values

quick start

installing

npm install json-fields-extractor

test

const extractJSON = require('json-fields-extractor');
const extractJSONObjectRes = extractJSON({a: 1}); // { a: [ 'number' ] }

Example

Input JSON Data:

{ 
  "str1": "str", 
  "object1": { 
    "obj1_field": "o1f" 
  }, 
  "array1": [ 
    { 
      "arr1_field": "a1f", 
      "arr2_field": 123 
    }, 
    { 
      "arr1_field": 123, 
      "arr2_field": 123 
    }, 
    { 
      "arr3_field": null 
    }, 
    "array_str" 
  ] 
}

Output result object:

{
  array1: [ 'array' ],
  'array1.$': [ 'object', 'string' ],
  'array1.$.arr1_field': [ 'number', 'string' ],
  'array1.$.arr2_field': [ 'number' ],
  'array1.$.arr3_field': [ 'null' ],
  object1: [ 'object' ],
  'object1.obj1_field': [ 'string' ],
  str1: [ 'string' ],
}