write your JSON in Javascript

json.js

JSON.stringify(eval(...)())

Why

Unquoted object keys and inline arithmetic can be handy. So can Array.prototype.map and friends.

What

json.js is a node script that reads a file or standard input, evaluates its contents as Javascript in an empty environment (except for that guaranteed by the language, e.g. JSON and Object), invokes the evaluated function, and prints to standard output the returned value as JSON.

How

$ ./json.js <<'END_JS' () => ({ foo: 'bar', ['hello' + 'there']: [1, 2, 3].map(n => `number${n}`) }) END_JS {"foo":"bar","hellothere":["number1","number2","number3"]}

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。