dgoffredo / jsonjs

write your JSON in Javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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"]}

About

write your JSON in Javascript

License:Other


Languages

Language:JavaScript 100.0%