Go through json multidimentional javascript

0

I have this json [{"id":1,"id_pai":null,"id_usuario":1,"ordem":1,"lado":"1"},[{"id":2,"id_pai":1,"id_usuario":2,"ordem":1,"lado":"1"},{"id":3,"id_pai":1,"id_usuario":3,"ordem":2,"lado":"2"}],[{"id":4,"id_pai":2,"id_usuario":4,"ordem":1,"lado":"1"}],[{"id":2,"id_pai":1,"id_usuario":2,"ordem":1,"lado":"1"},{"id":3,"id_pai":1,"id_usuario":3,"ordem":2,"lado":"2"}]]

I need to go through and transform that, in that, the missing data, I'll add later.

{ id: 0, parent: null, description: "Nivel do Peão", email: "[email protected]", groupTitleColor: "#4169e1", image: "demo/images/photos/q.png", itemTitleColor: "#4169e1", phone: "(19) 98111-9983", title: "Nome do Peão", label: "Nome do Peão" }

How do I route it with javascript?

Question 2, how do I avoid duplicate items?

    
asked by anonymous 04.02.2018 / 22:20

1 answer

0

Remember that these are json's within arrays: [{"id":1,"id_pai":null,"id_usuario":1,"ordem":1,"lado":"1"},[{"id":2,"id_pai":1,"id_usuario":2,"ordem":1,"lado":"1"},{"id":3,"id_pai":1,"id_usuario":3,"ordem":2,"lado":"2"}],[{"id":4,"id_pai":2,"id_usuario":4,"ordem":1,"lado":"1"}],[{"id":2,"id_pai":1,"id_usuario":2,"ordem":1,"lado":"1"},{"id":3,"id_pai":1,"id_usuario":3,"ordem":2,"lado":"2"}]]

Here's what you can do!

When it's array you can subscribe and get the final result! See:

			var text = [{"id":1,"id_pai":null,"id_usuario":1,"ordem":1,"lado":"1"},[{"id":2,"id_pai":1,"id_usuario":2,"ordem":1,"lado":"1"},{"id":3,"id_pai":1,"id_usuario":3,"ordem":2,"lado":"2"}],[{"id":4,"id_pai":2,"id_usuario":4,"ordem":1,"lado":"1"}],[{"id":2,"id_pai":1,"id_usuario":2,"ordem":1,"lado":"1"},{"id":3,"id_pai":1,"id_usuario":3,"ordem":2,"lado":"2"}]];

			text[0].cidade = "Cuiabá"; // Criando novo valor
			text[0].id = 99999; // Subscrevendo o valor antigo

			text = text; /* Subscreve o array de json antigos para o atual com mudanças */

			console.log(text); // Imprime no console do navegador

With JSON's:

var text = {
"employees":[
    {"firstName":"John", "lastName":"Doe"}, 
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
]
};

// Mudando valores
text.employees[0].firstName = "Maicon";
text.employees[0].lastName = "Ferreira";
// Adicionando valores
text.employees[0].cidade = "Cuiabá";
text.employees[0].estado = "Mato Grosso";
text.employees[0].pais = "Brasil";

// Prescrevendo valores
text = text;
// Imprimindo no console
console.log(text);

If I helped, do not forget to rate the correct answer!

    
05.02.2018 / 03:19