2json 中文文档教程

发布于 8年前 浏览 25 项目主页 更新于 3年前

json2

将 json 文档转换为 grep-able 和 sed-able 行

install

# json2 was already taken
npm install -g 2json

usage

# json2 args
json2 [file] [< or_file]

# 2json
# -p flag pretty prints json
2json [file] [< or_file] [-p --pretty]

# get package name
basename $(json2 package.json | grep '/name')

# change package name and reconvert lines to json using 2json
json2 < package.json | sed 's@\(/name\)/.*@\1/new-name@' | 2json -p

escapes for json2/2json

的简单实用程序以下内容被转义——按照规则在引号字符串中:

  • all forward slashes (/)
  • all index brackets ([ or ])
  • all strings that are just number characters (e.g. 00193425)

您必须转义字符串中的双引号,json2 会执行此操作。

backslash escapes for 2json

以下字符必须转义以处理使用反斜杠换行的问题,无论是否在引号中:

\ <- escape as \\
\n
\r
\f

notes

/ [] 由 json 行语法保留,如果在您的 json 中找到此类值,它们将用双引号引起来。

json2

simple utility for transforming json documents into grep-able and sed-able lines

install

# json2 was already taken
npm install -g 2json

usage

# json2 args
json2 [file] [< or_file]

# 2json
# -p flag pretty prints json
2json [file] [< or_file] [-p --pretty]

# get package name
basename $(json2 package.json | grep '/name')

# change package name and reconvert lines to json using 2json
json2 < package.json | sed 's@\(/name\)/.*@\1/new-name@' | 2json -p

escapes for json2/2json

The following are escaped--by being in quote strings, as per rules:

  • all forward slashes (/)
  • all index brackets ([ or ])
  • all strings that are just number characters (e.g. 00193425)

You must escape double quotes in strings, json2 does this.

backslash escapes for 2json

The following characters must be escaped to handle issues with newlines using backslashes, whether in quotes or not:

\ <- escape as \\
\n
\r
\f

notes

/ [ ] are reserved by the json line grammar, if such values are found in your json, they will be quoted in double quotes.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文