js-object-parser

1.0.1 • Public • Published

js-object-parser

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}}}"

Example / Usage

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" } }
    

Test

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

Creator

simonlovesyou

License (MIT)

Copyright (c) 2015 Simon Johansson

JohanssonLSimon@gmail.com

Website Twitter

Package Sidebar

Install

npm i js-object-parser

Weekly Downloads

23

Version

1.0.1

License

MIT

Last publish

Collaborators

  • simonlovesyou