JSON.stringify(eval(...)())
Unquoted object keys and inline arithmetic can be handy. So can
Array.prototype.map
and friends.
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.
$ ./json.js <<'END_JS'
() => ({
foo: 'bar',
['hello' + 'there']: [1, 2, 3].map(n => `number${n}`)
})
END_JS
{"foo":"bar","hellothere":["number1","number2","number3"]}