string-to-object-convert

1.0.4 • Public • Published

String to Object converter

Convert a string that contains an object.

For example

This will convert string like this to '{ appName: "JsonTest", keywords: { $in: [ "json", "string" ] } }'
Object like below
{
    appName: 'JsonTest',
    keywords: {
        $in: [ 'json', 'string' ]
    }
}

Assumptions

  • Strings inside the object do not contain commas. For example, this string values is not valid: "Hi, How are you"

Installation

$ npm install string-to-object-convert

Quick Start

import StringToObject from "string-to-object-convert";

const jsonString =
  '{ appName: "JsonTest", keywords: { $in: [ "json", "string" ] } }';
// IMPORTANT - String should provide within single quotes. String inside the object should provide within double quotes.

const resultObject = StringToObject.convertObject(jsonString);

License

MIT

Package Sidebar

Install

npm i string-to-object-convert

Weekly Downloads

3

Version

1.0.4

License

MIT

Unpacked Size

17.1 kB

Total Files

9

Last publish

Collaborators

  • chj-damon