Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONR. parse() problems with deep structures? #4

Open
legikaloz opened this issue Jan 13, 2015 · 1 comment
Open

JSONR. parse() problems with deep structures? #4

legikaloz opened this issue Jan 13, 2015 · 1 comment

Comments

@legikaloz
Copy link

Try the following:

testObj= {
    a:1,
    b:2,
    nested1:{
        nested2:{
            nested2Key:11,
            nested2Data:22
        }
    },
    somearray:[1,2,3,4,5,6,7,8,9,10],
    someArray2:[
        {sample:1},{sample:2},{sample:3}
    ]
};
testObj.ref1=testObj.nested1;
testObj.ref2=testObj.nested1.nested2;
testObj.ref3=testObj.someArray2[1];

toStr=JSONR.stringify(testObj);

toObj=JSONR.parse(toStr);

toObj.ref3 will be undefined

Browser:Chromium 38

@caipre
Copy link

caipre commented Feb 11, 2015

Working here using node 0.12.0:

Parses as:

{
  "a": 1,
  "b": 2,
  "nested1": {
    "nested2": {
      "nested2Key": 11,
      "nested2Data": 22
    }
  },
  "somearray": [
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10
  ],
  "someArray2": [
    {
      "sample": 1
    },
    {
      "sample": 2
    },
    {
      "sample": 3
    }
  ],
  "ref1": {
    "nested2": {
      "nested2Key": 11,
      "nested2Data": 22
    }
  },
  "ref2": {
    "nested2Key": 11,
    "nested2Data": 22
  },
  "ref3": {
    "sample": 2
  }
// test.js
var jsonr = require('jsonr');

testObj= {
    a:1,
    b:2,
    nested1:{
        nested2:{
            nested2Key:11,
            nested2Data:22
        }
    },
    somearray:[1,2,3,4,5,6,7,8,9,10],
    someArray2:[
        {sample:1},{sample:2},{sample:3}
    ],
};
testObj.ref1=testObj.nested1;
testObj.ref2=testObj.nested1.nested2;
testObj.ref3=testObj.someArray2[1];

toStr = jsonr.stringify(testObj);
console.log(jsonr.revealReferences(toStr), "\n");

toObj = jsonr.parse(toStr);
console.log(JSON.stringify(toObj, null, 2));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants