darkrc/bin/jsonidx

15 lines
336 B
Text
Raw Permalink Normal View History

2020-06-26 09:24:32 +00:00
#!/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