2
--=========================================================================
4
-- Copyright Insight Software Consortium
6
-- Licensed under the Apache License, Version 2.0 (the "License");
7
-- you may not use this file except in compliance with the License.
8
-- You may obtain a copy of the License at
10
-- http://www.apache.org/licenses/LICENSE-2.0.txt
12
-- Unless required by applicable law or agreed to in writing, software
13
-- distributed under the License is distributed on an "AS IS" BASIS,
14
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
-- See the License for the specific language governing permissions and
16
-- limitations under the License.
18
--=========================================================================
20
-- This script parses a JSON file, and print specified json fields provided by JSON paths.
22
-- It is currently expected that path specified is the lua table access
23
-- string to the correct field. There currently is no real validation
26
package.path = debug.getinfo(1).source:match("@?(.*/)")..'?.lua;' .. package.path
31
print("usage: "..arg[0].." [json file] [json path]+")
35
--print("Reading \""..arg[1].."\"...")
37
local f = assert(io.open(arg[1]))
39
local str = f:read("*all")
42
json_table = decode(str)
48
cmd = loadstring("return json_table."..json_path)
50
io.stderr:write("Warning: bad path -> "..json_path.."\n")
51
bad_count = bad_count+1
55
io.stderr:write(json_path.." NOT FOUND\n")
57
print(json_path..": \""..cmd().."\"")