我想在JSON文件中存储一些sql字符串。这就是JSON文件在我的理想世界中的样子
[
"select t.index1, t.title, t.description, t.insertDate
from myTable t
join anotherTable t2 on t.index1 = t2.fIndex
where t2.active = 1",
...
]
明显的限制是JSON和javascript不支持多行字符串。
我想避免这样做:
[
"select t.index1, t.title, t.description, t.insertDate\nfrom myTable t\njoin anotherTable t2 on t.index1 = t2.fIndex\nwhere t2.active = 1",
...
]
我看到一个人这样做了,这也不理想:
[
["select t.index1, t.title, t.description, t.insertDate",
"from myTable t",
"join anotherTable t2 on t.index1 = t2.fIndex",
"where t2.active = 1"],
...
]
然后在他的翻译程序中他使用了myMultilineStringInArrayForm.join("\n")
。
我想知道是否有人为此目的有任何关于模板字符串工作(或计划在将来工作)的信息,如下所示:
[
`select t.index1, t.title, t.description, t.insertDate
from myTable t
join anotherTable t2 on t.index1 = t2.fIndex
where t2.active = 1`,
...
]
注意我在ES6的模板文字中使用了反引号(`
),显然变量的插值对于存储的JSON不起作用,但是这个文字的多行特征是我感兴趣的。
请注意,这个问题类似于这个6岁的问题:Multiline strings in JSON
我再次问,因为我想知道`
语法是否已经计划好或者已经有效了。
我很感激这方面的帮助