Convert strings representing paths or objects with a path and optional value to a JSON object.
Install
$ npm install jsonify-paths
Usage
const jsonifyPaths = ;
From a string
jsonifyPaths;// => "a": "bb": "ccc": {}
From an array of strings
jsonifyPaths;// => "I am": "not": "a number": {} "a": "free man!": {}
From an object
jsonifyPaths;// => "a": "bb": "ccc": {}
Providing value
jsonifyPaths;// => "a": "bb": "ccc": "foo"
From an array of objects
jsonifyPaths;// => "a": "bb": "ccc": {} "d": {} "e": {}
Providing values (optional)
jsonifyPaths;// => "a": "bb": "ccc": "foo" "d": {} // => default value "e": false "f": "g": "" "h": 123
Options
slash
)
Use custom delimiters (default: jsonifyPaths;jsonifyPaths;jsonifyPaths
true
)
Ignore consecutive, leading and trailing delimiters (default: jsonifyPaths;jsonifyPaths;jsonifyPaths;jsonifyPaths;jsonifyPaths;jsonifyPaths;// => "a": "b": "c": {}
true
)
Ignore spaces around delimiters (default: jsonifyPaths;// => "Lyon": "Reykjavik": "Vienna": "On Time"
Forcing option to false
jsonifyPaths;// =>'I ': ' am not a ': ' number': {}
{}
)
Change default value (default: Default value is used when value is not set for an object
jsonifyPaths;// => "Lyon": "Berlin": "Rome": "Scheduled" // => default value "Geneva": 'On Time' "Bangkok": "Tokyo": 'Delayed' ;
Mix objects and strings
const res = jsonifyPaths; // => "Lyon": "Berlin": "Rome": "Scheduled" "Geneva": "On Time" "Paris": "Scheduled" "Bangkok": "Tokyo": "Scheduled"