Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

ttlong3103/parse-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published