After a manipultion of a JSON object i have a string like:

[{ContextID:'7',Title:'Rona',TypeId:'1',Children:[{ContextID:'8',Title:'Site internet',TypeId:'2',Children:'null'},{ContextID:'9',Title:'Magasins',TypeId:'2',Children:[{ContextID:'10',Title:'RONA Quincaillerie Delorimier Inc.',TypeId:'4',Children:[{ContextID:'11',Title:'Caisse',TypeId:'3',Children:[{ContextID:'12',Title:'Retour marchandise',TypeId:'3',Children:'null'}]}]}]}]

I want to transform it an array in javascript to pass it to angularjs-ui-tree like this one. I have tried JSON.parse() but it doesn't work

[{ContextID:'7',Title:'Rona',TypeId:'1',Children:[{ContextID:'8',Title:'Site internet',TypeId:'2',Children:'null'},{ContextID:'9',Title:'Magasins',TypeId:'2',Children:[{ContextID:'10',Title:'RONA Quincaillerie Delorimier Inc.',TypeId:'4',Children:[{ContextID:'11',Title:'Caisse',TypeId:'3',Children:[{ContextID:'12',Title:'Retour marchandise',TypeId:'3',Children:'null'}]}]}]}]
share|improve this question
1  
Why don't you properly format and formulate your question first? – Florian Nov 26 '15 at 15:58
    
What kind of sorcery is this? Please read how to ask page before asking any question(s) in the future. Please. – Gökay Gürcan Nov 26 '15 at 16:04
    
I feel like JSON.parse() should work. What did you try, what were the results? – OscuroAA Nov 26 '15 at 16:11

I ran the JSON you provided through a JSON validator and received the following error message:

The JSON input is NOT valid according to RFC 4627 (JSON specification). Unexpected End Of File position 376: null

It appears that your JSON is missing }] at the end. By adding those two characters, the validator verified that the JSON string is valid.

I'm not sure what you are asking for related to angularjs-ui-tree, but having valid JSON is a step in the right direction.

share|improve this answer

Your JSON string might be malformed. Try wrapping both keys and values on double quotes (").

share|improve this answer

After running your JSON through JSONLint I realized you need to use double quotes around your keys (ContextID etc) to properly parse it.

You might also want to consider not putting quotes around numeric values.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.