How to count items in JSON object using command line?

I’m getting this kind of JSON reply from a curl command:

[
  {
    "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) ?

6 Answers
6

Leave a Comment