我从curl指挥部得到这样的JSON回复:

[
  {
    "cid": 49,
    "pyn": "yi4",
    "hans": "亿",
    "hant": "億",
    "tid": 68,
    "l10n": "cent million",
    "pid": 1,
    "pos": "num",
    "pos_txt": ""
  },
  {
    "cid": 50,
    "pyn": "yi4",
    "hans": "亿",
    "hant": "億",
    "tid": 69,
    "l10n": "100 millions",
    "pid": 1,
    "pos": "num",
    "pos_txt": ""
  }
]

How can I count the number of items in the array (here 2), using Bash or a command line (e.g. underscore) ?

推荐答案

Just throwing another solution in the mix...

Try jq, a lightweight and flexible command-line JSON processor:

jq length /tmp/test.json

Prints the length of the array of objects.

Json相关问答推荐

嵌套自定义解组

JSON:将项';S键/名称移动到属性中,并使用JQ将其转换为数组

Bash和echo命令出现意外结果

如何将加权边列表导出到JSON树?

如何创建生成两个不同对象的JSON数组的SQL查询?

Jolt变换将字段移动到数组的每个元素中

用于参考的Jolt变换

使用本地 JSON api react TS Axios

jq: Select 何时来自另一个数组的值与此 json 中的值匹配

使用 jq 获取特定键的所有父键

如果有 1 个元素,如何防止 ConvertFrom-Json 折叠嵌套数组

如何在 onClick 事件处理程序中识别在同一 map 上绘制的多个多边形中的哪个(使用 react-leaflet)被单击?

JQuery,使用 GET 方法发送 JSON 对象

如何使用 jackson 反序列化为 Kotlin 集合

从 Postgres 中的 json 对象中提取键、值

是否可以将数据写入本地 json 文件,除了Angular 之外什么都没有?

如何使用 Jackson 注释从 HttpResponse 反序列化 JSON 对象?

如何让 javascript 从 .json 文件中读取?

AJAX 将 JavaScript 字符串数组发布到 JsonResult 作为 List 总是返回 Null?

类型是接口或抽象类,不能实例化