Add JSON-Index script (LuaJIT + cJSON)
This commit is contained in:
parent
a25f01d36b
commit
4d9c1ab935
1 changed files with 14 additions and 0 deletions
14
bin/jsonidx
Executable file
14
bin/jsonidx
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env luajit
|
||||
|
||||
local json = require 'cjson'
|
||||
|
||||
local input = assert(json.decode(io.stdin:read("a*")))
|
||||
|
||||
for i, chain in ipairs{...} do
|
||||
local current = input
|
||||
for index in chain:gmatch("[^.]+") do
|
||||
index = tonumber(index) or index
|
||||
current = type(current)=="table" and current[index] or nil
|
||||
end
|
||||
print(json.encode(current))
|
||||
end
|
Loading…
Reference in a new issue