Skip to content

Instantly share code, notes, and snippets.

@narate
Created August 29, 2015 14:23
Show Gist options
  • Save narate/c9299b4bc60828e1c95e to your computer and use it in GitHub Desktop.
Save narate/c9299b4bc60828e1c95e to your computer and use it in GitHub Desktop.
Just one line json
#!/usr/bin/env luajit
-- author : Narate Ketram
-- github.com/narate
-- usage :
--[[
echo '
{
"query": {
"bool": {
"must": [
{
"term": {
"plugin": "interface"
}
},
{
"term": {
"uid": 1113
}
}
]
}
}
}
' | one_line_json
{"query":{"bool":{"must":[{"term":{"plugin":"interface"}},{"term":{"uid":1113}}]}}}
--]]
local cjson = require 'cjson.safe'
local data = io.read('*all')
local json = cjson.decode(data)
if not json then
print('Invalid json')
return
end
print(cjson.encode(json))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment