turn string into javascript array

0

Good afternoon,

I have the following string

[{"programa":"teste"},{"programa":"Aprender"},{"programa":"outro teste","indice":"0;1;0"}][{"programa":"Programando 1","indice":"1;2;3"},{"programa":"hostórico","indice":"1;2;2"},{"programa":"análise","indice":"1;2;1"}]

How do I get array through this string?

    
asked by anonymous 23.07.2018 / 20:01

1 answer

3

Your string JSON seems to be badly formatted, there are two badly defined arrays (this gives error: ][ ).

I made a small change to be a valid array and converted to object using JSON.parse :

var x = '{"1":[{"programa":"teste"},{"programa":"Aprender"},{"programa":"outro teste","indice":"0;1;0"}],"2":[{"programa":"Programando 1","indice":"1;2;3"},{"programa":"hostórico","indice":"1;2;2"},{"programa":"análise","indice":"1;2;1"}]}';

var o = JSON.parse(x);
console.log(o);
    
23.07.2018 / 20:37