Can there be a multiline key/value in json?

370 views Asked by At

Is somethhing like this possible in json

let a = {
    "awe
     sdsds" : "eweq
               dfs
               ewewew"
}

can i have multiline strings as key and value

I tried and got this icon at newline for key and \n this at newline for value

1

There are 1 answers

0
Yury Tarabanko On BEST ANSWER

This is not "JSON", it is object literal.

If you are having a literal you can use string literals and computed properties if you really want to have this kind of keys. Otherwise you'd need to use escape seq \n (see the result of JSON.stringify)

let a = {
    [`awe
     sdsds`] : `eweq
               dfs
               ewewew`
}

console.log(a[`awe
     sdsds`])

console.log(JSON.stringify(a))