I have a JSON object of format:
obj {
name: "abc" ,
entriesList : "list of entry obj" ,
propertiesList : "list of properties obj"
};
where entry is also another object
entry {
info : "data obj" ,
age : "15" ,
subjects : "5"
}
properties {
a : "a" ,
b : "b"
}
data {
c : "c" ,
d : "d"
}
Using JSON.stringify() it is giving error
cyclic object value
How should I convert my object to JSON string?
Mariusz Jamro
31.9k25 gold badges129 silver badges170 bronze badges
-
1Isn't JSON.parse reverse of JSON.stringify i.e. converting JSON string to JSON obj? whereas my need is stringilyuser3505394– user35053942015年05月26日 03:47:30 +00:00Commented May 26, 2015 at 3:47
-
Is your JSON cyclic? Is the original 'obj' an entry object?crc442– crc4422015年05月26日 03:52:08 +00:00Commented May 26, 2015 at 3:52
-
@crc442 No, it does't looks cyclic to me. Original obj is not an entry object.user3505394– user35053942015年05月26日 03:53:59 +00:00Commented May 26, 2015 at 3:53
-
Can you post the actual data?crc442– crc4422015年05月26日 03:55:14 +00:00Commented May 26, 2015 at 3:55
-
I can't post actual data but I am trying to come up with more clear analogy.user3505394– user35053942015年05月26日 04:13:16 +00:00Commented May 26, 2015 at 4:13
1 Answer 1
I can't see a cycle from your example, but the idea is to not include cyclic references in your object. I mean to avoid something like this:
var a = {}, b = {};
a.child = b;
b.child = a; //This will cause a cyclic reference when calling JSON.stringify both on a and b object
answered May 26, 2015 at 3:50
edrian
4,5315 gold badges34 silver badges35 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
user3505394
I understood not to include cycles references and I can't see cyclic references as well.But I am getting error as cyclic object value.
lang-js