santiago arizti santiago arizti - 18 days ago 8
JSON Question

JSON and Template Literals for multiline strings

I want to store some sql strings in a JSON file.
This is how the JSON file looks in my ideal world

[
"select t.index1, t.title, t.description, t.insertDate
from myTable t
join anotherTable t2 on t.index1 = t2.fIndex
where t2.active = 1",
...
]


The obvious limitation is that JSON and javascript don't support multiline strings.

I want to avoid doing this:

[
"select t.index1, t.title, t.description, t.insertDate\nfrom myTable t\njoin anotherTable t2 on t.index1 = t2.fIndex\nwhere t2.active = 1",
...
]


I saw a guy that did this, which is not ideal either:

[
["select t.index1, t.title, t.description, t.insertDate",
"from myTable t",
"join anotherTable t2 on t.index1 = t2.fIndex",
"where t2.active = 1"],
...
]


And then in his interpreter program he used
myMultilineStringInArrayForm.join("\n")
.

I was wondering if anyone has any information about Template strings working (or planned to work in the future) for such purpose, like this:

[
`select t.index1, t.title, t.description, t.insertDate
from myTable t
join anotherTable t2 on t.index1 = t2.fIndex
where t2.active = 1`,
...
]


Notice I iused backticks (
`
) like in Template Literals from ES6, obviously the interpolation of variables would not work for stored JSON, but the multiline feature of this literals is what I am interested in.

Notice that this question is similar to this 6 year old question: Multiline strings in JSON

I asked again because I wanted to know if the
`
syntax was planned or already worked since that time.

I appreciate the help with this

Answer

Looks like my best choice for having a readable storage format is XML. I was trying to stay away from XML and thought that JSON had multiline strings in its future due to the ` syntax, but no

Comments