A library for parsing a string to a javascript object.
Main difference between the JSON.parse function and this function is that js-object-parser will be able to parse
"{A:b, C:d, E:{any-object:{a:1, b:2}}}"
, where JSON.parse fails as it requires every property to be wrapped in quotationmarks, i.e:
"{"A":"b", "C":"d", "E":{"any-object":{"a":1, "b":2}}}"
Add it to your project by
npm install js-object-parser
In your program
import objectParser from 'js-object-parser';
console.log(objectParser.parse('{A:"b", C:[1,2,"3"]}'));
//Outputs: {A: "b", C: [1,2,"3"]}
It can handle nested objects:
console.log(objectParser.parse('{A:{BCDEF:{G:"h"}, I:"j"}}'));
//Outputs: { A: { BCDEF: { G: "h" }, I: "j" } }
For testing, run
# Clone repository
git clone https://github.com/simonlovesyou/js-object-parser.git
# Navigate into project folder
cd js-object-parser
# Install dependencies
npm install
# Run tests
npm test
Copyright (c) 2015 Simon Johansson