Tools, FAQ, Tutorials:
JSON-stringify-space.html - JSON.stringify() Friendly Spaced
How to call the JSON.stringify() function with space argument to generate JSON text strings indented with friendly spaces?
✍: FYIcenter.com
If you call JSON.stringify() without the "space" argument,
the JSON text string will be generated in a single line,
with no line breaks and space indentions.
If you want to break lines after each array element or object property, you need to the "space" argument in the JSON.stringify() call.
Here is JavaScript example that compares output JSON text strings generated with different "space" options:
<!-- JSON-stringify-space.html
Copyright (c) FYIcenter.com
-->
<html>
<body>
<script type="text/javascript">
document.write("<p>JSON.stringify() Replacer to Transform Values:</p>");
document.write("<pre>");
str = '["first", {"name": "Jay", "friends": ["Joe", "Kim"]}]';
document.write("Input = "+str+"\n");
json = JSON.stringify(JSON.parse(str));
document.write("Output 1 = "+json+"\n");
json = JSON.stringify(JSON.parse(str), null, 3);
document.write("Output 2 = "+json+"\n");
json = JSON.stringify(JSON.parse(str), null, "___");
document.write("Output 3 = "+json+"\n");
document.write("</pre>");
</script>
</body>
</html>
Open the above code in a Web browser. You see the following output:
JSON.stringify() Replacer to Transform Values:
Input = ["first", {"name": "Jay", "friends": ["Joe", "Kim"]}]
Output 1 = ["first",{"name":"Jay","friends":["Joe","Kim"]}]
Output 2 = [
"first",
{
"name": "Jay",
"friends": [
"Joe",
"Kim"
]
}
]
Output 3 = [
___"first",
___{
______"name": "Jay",
______"friends": [
_________"Joe",
_________"Kim"
______]
___}
]
⇒ JSON Validation Online Tools
⇐ JSON-stringify-Filter.html - JSON.stringify() Array Replacer
2023-09-05, ∼2054🔥, 0💬
Popular Posts:
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...
How To Read the Entire File into a Single String in PHP? If you have a file, and you want to read th...
How to add request URL Template Parameters to my Azure API operation 2017 version to make it more us...
How to build a PHP script to dump Azure AD 2.0 Authentication Response? If you are use the Azure-AD-...