parse-object

1.0.1 • Public • Published

parse-object

Support parsing string contains object-liked syntax that can not be parsed by JSON.parse()

NPM JavaScript Style Guide

Sometimes, you receive string that has value like "{ sort: { date: 'DES' } }" and you want to parse it into an object. First solution would be, of course, JSON.parse(). However, your string is not valid JSON-formatted string so JSON.parse() will fail to parse it. That is the reason why I made this parse-object module.

Install

npm install --save parse-object

Usage

const parse = require('parse-object');

const str = "{ sort: { date: 'DES' } }";
console.log(parse(str)); // { sort: { date: 'DES' } }
console.log(JSON.parse(str)); // raise error

parse-object can also parse any output from JSON.stringify()

const parse = require('parse-object');

const stringified = JSON.stringify({ name: "me", id: 123456 });
console.log(parse(stringified)); //  { name: "me", id: 123456 }

Readme

Keywords

Package Sidebar

Install

npm i parse-object

Weekly Downloads

5

Version

1.0.1

License

ISC

Unpacked Size

12.2 kB

Total Files

8

Last publish

Collaborators

  • ttlong