sidorares / json-bigint

JSON.parse/stringify with bigints support
MIT License
808 stars 192 forks source link

Error occurred when use parse function. #12

Closed zhaotoday closed 8 years ago

zhaotoday commented 8 years ago

import JSON from 'json-bigint';

const json = JSON({ strict: false, storeAsString: true });

const obj = '{"a":"{\"b\":1}"}'; // it works well when: const obj = '{"a":"{\"b\":1}"}'; json.parse(obj);

Why there must be double \?

sidorares commented 8 years ago

yes, your input is not a valid json

instead of '{"a":"{\"b\":1}"}' it should be '{"a":{\"b\":1}}' ( and you don't need to escape " inside 's, so this is ok, too:

  const obj = '{"a":{"b":1}}';
  console.log(JSON.parse(obj))