'Add newline after each key, value using JSON.stringify()
I want to add a newline after each key value pair in an object using JSON.stringify()
In my actual code I will be getting a lot of key value pairs and having the new lines makes it easier to read.
Example code is:
let test = {'key' : ['one', 'two', 'three'], 'keyTwo' : ['one', 'two', 'three']}
let testOne = JSON.stringify(test, null, '\t')
console.log(testOne)
outputs:
{
"key": [
"one",
"two",
"three"
],
"keyTwo": [
"one",
"two",
"three"
]
}
I want:
{
"key": [
"one",
"two",
"three"
],
// <----- newline here
"keyTwo": [
"one",
"two",
"three"
]
}
I have tried
let test = {'key' : ['one', 'two', 'three'] + "\\n", 'keyTwo' : ['one', 'two', 'three']+ "\\n"}
let testOne = JSON.stringify(test, null, '\t\n')
Neither work
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
