{"action":"closed","issue":{"url":"https://api.github.com/repos/WebReflection/circular-json/issues/21","labels_url":"https://api.github.com/repos/WebReflection/circular-json/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/WebReflection/circular-json/issues/21/comments","events_url":"https://api.github.com/repos/WebReflection/circular-json/issues/21/events","html_url":"https://github.com/WebReflection/circular-json/issues/21","id":115211412,"number":21,"title":"Nested structure skips one level in serialized json path, won't deserialize","user":{"login":"samuelneff","id":1799385,"avatar_url":"https://avatars.githubusercontent.com/u/1799385?v=3","gravatar_id":"","url":"https://api.github.com/users/samuelneff","html_url":"https://github.com/samuelneff","followers_url":"https://api.github.com/users/samuelneff/followers","following_url":"https://api.github.com/users/samuelneff/following{/other_user}","gists_url":"https://api.github.com/users/samuelneff/gists{/gist_id}","starred_url":"https://api.github.com/users/samuelneff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samuelneff/subscriptions","organizations_url":"https://api.github.com/users/samuelneff/orgs","repos_url":"https://api.github.com/users/samuelneff/repos","events_url":"https://api.github.com/users/samuelneff/events{/privacy}","received_events_url":"https://api.github.com/users/samuelneff/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-05T05:17:31Z","updated_at":"2015-11-06T00:25:20Z","closed_at":"2015-11-06T00:25:20Z","body":"Love this library and it's been working really well for a while. I recently ran into a deserialization problem with a dynamically generated structure with a lot of parent and cross references. The problem is actually in serialization, not deserialization.\r\n\r\nI was able to reduce the structure and still reproduce the problem with this example:\r\n\r\n```js\r\nvar original = {\r\n    \"a1\": {\r\n        \"a2\": [\r\n            // ~a1\r\n        ],\r\n        \"a3\": [\r\n            {\r\n                \"name\": \"whatever\"\r\n            }\r\n        ]\r\n    },\r\n    \"a4\": [\r\n        // ~a1~a3[0]\r\n    ]\r\n};\r\n\r\noriginal.a1.a2[0] = original.a1;\r\noriginal.a4[0] = original.a1.a3[0];\r\n\r\nvar json = circularJson.stringify(original);\r\n\r\nconsole.log(json);\r\n\r\nvar restored = circularJson.parse(json);\r\n```\r\n\r\nThe circular JSON that gets generated from above is this:\r\n\r\n```js\r\n{\"a1\":{\"a2\":[\"~a1\"],\"a3\":[{\"name\":\"whatever\"}]},\"a4\":[\"~a1~a2~a3~0\"]}\r\n```\r\n\r\nBut the JSON should be this:\r\n\r\n```js\r\n{\"a1\":{\"a2\":[\"~a1\"],\"a3\":[{\"name\":\"whatever\"}]},\"a4\":[\"~a1~a2~0~a3~0\"]}\r\n                                                             ↑ missing part\r\n```\r\n\r\nDeserializing the generated (incorrect) circular json gives this error:\r\n\r\n```\r\n\"C:\\Program Files\\nodejs\\node.exe\" tools\\scratchpad.js\r\n\r\n{\"a1\":{\"a2\":[\"~a1\"],\"a3\":[{\"name\":\"whatever\"}]},\"a4\":[\"~a1~a2~a3~0\"]}\r\n\r\nc:\\src\\node_modules\\circular-json\\build\\circular-json.node.js:110\r\n  for(var i = 0, length = keys.length; i < length; current = current[\r\n                                                                    ^\r\nTypeError: Cannot read property '0' of undefined\r\n    at retrieveFromPath (c:\\src\\node_modules\\circular-json\\build\\circular-json.node.js:110:69)\r\n    at regenerate (c:\\src\\node_modules\\circular-json\\build\\circular-json.node.js:160:37)\r\n    at regenerateArray (c:\\src\\node_modules\\circular-json\\build\\circular-json.node.js:134:18)\r\n    at regenerate (c:\\src\\node_modules\\circular-json\\build\\circular-json.node.js:151:5)\r\n    at regenerateObject (c:\\src\\node_modules\\circular-json\\build\\circular-json.node.js:142:22)\r\n    at regenerate (c:\\src\\node_modules\\circular-json\\build\\circular-json.node.js:169:13)\r\n    at Object.<anonymous> (c:\\src\\node_modules\\circular-json\\build\\circular-json.node.js:123:29)\r\n    at Object.parse (native)\r\n    at Object.parseRecursion [as parse] (c:\\src\\node_modules\\circular-json\\build\\circular-json.node.js:182:15)\r\n    at Object.<anonymous> (c:\\src\\tools\\scratchpad.js:106:29)\r\n\r\nProcess finished with exit code 1\r\n```\r\n\r\nThanks,\r\n\r\nSam\r\n"}}