Circular-json

circular-json

Handle circular JSON references with ease!

You would have come acorss TypeError: Converting circular structure to JSON if you have been handling JSONs for a while now, circular-json serializes and deserializes otherwise valid JSON objects containing circular references into and from a specialized JSON format.

Get it: npm install circular-json

Sample usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
'use strict';

const
  CircularJSON = require('circular-json'),
  obj = { foo: 'bar' },
  str
;

obj.self = obj;
const str = CircularJSON.stringify(obj);

// "{\"foo\":\"bar\",\"self\":\"~\"}"

/*
JSON.stringify(obj); would have resulted in:
TypeError: Converting circular structure to JSON
*/

GIF FTW!

circular-json

Suggest a module

Comments