Answer the question
In order to leave comments, you need to log in
JSON holding functions?
Are there ready-made functions to cast JSON like
[
{ "a" : "1", "b" : "1", "c" : "0" },
{ "a" : "1", "b" : "2", "c" : "1" },
{ "a" : "1", "b" : "3" },
{ "a" : "2", "b" : "1", "c" : "2" },
{ "a" : "2", "b" : "1", "c" : "3" }
]
[{
"a": [{
"1": [{
"b": [{
"1": { "c": "0" },
"2": { "c": "1" },
"3": { "c": "" }
}]
}]
}],
"2": [{
"b": [{
"1": [
{ "c": "2" },
{ "c": "3" }
]
}]
}]
}]
[{
"1": {
"1": "0",
"2": "1",
"3": ""
},
"2": [{
"1": ["2", "3"]
}]
}]
Answer the question
In order to leave comments, you need to log in
No. There are no ready-made functions.
Although this is not difficult to do. The main thing is to know what you want. It's not obvious from your examples. They do not follow a pattern and a bunch of inconsistencies. You must have been in a hurry when you put them together. So I'm not even sure that you yourself know what you need. But on the other hand, I am sure that as soon as you start doing (or start compiling technical specifications), you will immediately understand what you need and what you do not need.
When you make your function, feel free to come back to this question and check how much the result of the function differs from your examples.
Use JSON.stringify
it <pre>
to the fullest.
JSON.stringify(jsObj, null, "\t"); // добавит отступы с табами
JSON.stringify(jsObj, null, 4); // добавит отступы с 4 пробелами
<pre id='formated'></pre>
<script type="text/JavaScript">
var json = JSON.parse('{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}');
var formated = document.getElementById('formated');
formated.innerHTML = JSON.stringify(json, null, 4);
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question