From 4d9c1ab9352eb182a860a4db7bb8712fe131aaf7 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Fri, 26 Jun 2020 11:24:32 +0200 Subject: [PATCH] Add JSON-Index script (LuaJIT + cJSON) --- bin/jsonidx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 bin/jsonidx diff --git a/bin/jsonidx b/bin/jsonidx new file mode 100755 index 0000000..df025a4 --- /dev/null +++ b/bin/jsonidx @@ -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