json-fields-extractor
v0.0.4
Published
extract schema / all fields in JSON data
Downloads
6
Maintainers
Readme
JSON fields extractor
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 Typesvalue
extract value
options.skip_keys_sort
(defaultfalse
) skip sorting of result keysoptions.skip_values_sort
(defaultfalse
) 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' ],
}