What are good CLI tools for JSON?

后端 未结 8 1218
难免孤独
难免孤独 2021-01-30 00:45

General Problem

Though I may be diagnosing the root cause of an event, determining how many users it affected, or distilling timing logs in order to assess the perform

相关标签:
8条回答
  • 2021-01-30 01:37

    Fortunately in XML-land, we have wonderful technologies like XPath, XQuery, and XSLT to help us.
    [...]
    So this leads me to my question: are there any tools like this for JSON?

    If you ask me, Xidel is exactly what you're looking for.

    Xidel is a command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern templates. It can also create new or transformed XML/HTML/JSON documents.

    Query:

    xidel -s "input.json" \
    -e '
      $json/avg(
        count(
          (phoneNumber)()
        )
      )
    '
    

    or

    xidel -s "input.json" -e '$json/avg(count((phoneNumber)()))'
    

    Output:

    2
    
    0 讨论(0)
  • 2021-01-30 01:38

    I just found this:

    http://stedolan.github.com/jq/

    "jq is a lightweight and flexible command-line JSON processor."

    2014 update:

    @user456584 mentioned:

    There's also the 'json' command (e.g. 'jsontool'). I tend to prefer it over jq. Very UNIX-y. Here's a link to the project: github.com/trentm/json –

    in the json README at http://github.com/trentm/json there is a long list of similar things

    • jq: http://stedolan.github.io/jq/
    • json:select: http://jsonselect.org/
    • jsonpipe: https://github.com/dvxhouse/jsonpipe
    • json-command: https://github.com/zpoley/json-command
    • JSONPath: http://goessner.net/articles/JsonPath/, http://code.google.com/p/jsonpath/wiki/Javascript
    • jsawk: https://github.com/micha/jsawk
    • jshon: http://kmkeen.com/jshon/
    • json2: https://github.com/vi/json2
    • fx: https://github.com/antonmedv/fx
    0 讨论(0)
提交回复
热议问题