json

用于在 Unix 命令行中处理 JSON 的 "json" 命令。「A "json" command for massaging JSON on your Unix command line.」

  • 所有者: trentm/json
  • 平台:
  • 許可證: Other
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

json is a fast CLI tool for working with JSON. It is a single-file node.js
script with no external deps (other than
node.js itself). A quick taste:

$ echo '{"foo":"bar"}' | json
{
  "foo": "bar"
}

$ echo '{"foo":"bar"}' | json foo
bar

$ echo '{"fred":{"age":42}}' | json fred.age    # '.' for property access
42

$ echo '{"age":10}' | json -e 'this.age++'
{
  "age": 11
}

# `json -ga` (g == group, a == array) for streaming mode
$ echo '{"latency":32,"req":"POST /widgets"}
{"latency":10,"req":"GET /ping"}
' | json -gac 'this.latency > 10' req
POST /widgets

Features:

  • pretty-printing JSON
  • natural syntax (like JS code) for extracting particular values
  • get details on JSON syntax errors (handy for config files)
  • filter input JSON (see -e and -c options)
  • fast stream processing (see -ga)
  • JSON validation
  • in-place file editing

See https://trentm.com/json for full docs and examples as a man page.

Follow @trentmick
for updates to json.

Installation

  1. Get node.

  2. npm install -g json

    Note: This used to be called 'jsontool' in the npm registry, but as of
    version 8.0.0 it has taken over the 'json' name. See npm Package
    Name
    below.

OR manually:

  1. Get the 'json' script and put it on your PATH somewhere (it is a single file
    with no external dependencies). For example:

     cd ~/bin
     curl -L https://github.com/trentm/json/raw/master/lib/json.js > json
     chmod 755 json
    

You should now have "json" on your PATH:

$ json --version
json 9.0.0

WARNING for Ubuntu/Debian users: There is a current bug in Debian stable
such that "apt-get install nodejs" installed a nodejs binary instead of a
node binary. You'll either need to create a symlink for node, change the
json command's shebang line to "#!/usr/bin/env nodejs" or use
chrislea's PPA as
discussed on issue #56. You can also do "apt-get install nodejs-legacy" to install symlink for node with apt.

Test suite

npm test   # or 'make test'

This is using node-tap, so you can use all its options,
for example filtering which tests to run:

npm test -- -g stream

License

MIT (see the fine LICENSE.txt file).

Module Usage

Since v1.3.1 you can use "json" as a node.js module:

var json = require('json');

However, so far the module API isn't that useful and the CLI is the primary
focus.

npm Package Name

Once upon a time, json was a different thing (see zpoley's json-command
here
), and this module was
called jsontool in npm. As of version 8.0.0 of this module, npm install json
means this tool.

If you see documentation referring to jsontool, it is most likely
referring to this module.

Alternatives you might prefer

主要指標

概覽
名稱與所有者trentm/json
主編程語言JavaScript
編程語言Makefile (語言數: 5)
平台
許可證Other
所有者活动
創建於2011-02-11 00:35:08
推送於2024-01-23 13:41:38
最后一次提交2021-04-26 22:10:48
發布數53
最新版本名稱11.0.0 (發布於 2021-04-26 19:27:25)
第一版名稱1.1.3 (發布於 2011-02-14 23:32:04)
用户参与
星數1.6k
關注者數28
派生數121
提交數356
已啟用問題?
問題數125
打開的問題數41
拉請求數16
打開的拉請求數10
關閉的拉請求數18
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?