json - 用 jq 解析一组 JSON 对象
问题描述
A有一大块JSON我正在尝试解析,看起来基本上像
{
"order": [
"hash1",
"hash2"
],
"posts": {
"hash4": {
"id": "hash4",
"message": "lorem ipsem"
},
"hash5": {
"id": "hash5",
"message": "dolor sit amet"
},
"hash6": {
"id": "hash6",
"message": "consectetur adipiscing elit"
}
}
}
到目前为止我一直在处理这个问题的方式只是 grep 消息
$ grep 'message' jq_dat.json
"message": "lorem ipsem"
"message": "dolor sit amet"
"message": "consectetur adipiscing elit"
这适用于我目前的目的,但我想知道如何使用jq
. IE
$ jq .posts.<something>.message < jq_dat.json
"lorem ipsem"
"dolor sit amet"
"consectetur adipiscing elit"
我尝试使用[]
and{}
代替something
,但是它们都吐回编译错误。
解决方案
你只是有一个太多的点
jq .posts[].message < jq_dat.json
推荐阅读
- python - 如何捕获基于 ipython 的 jupyter notebook 中打印的所有内容?
- python - How to use variable names iteratively in a loop in python/pandas
- sharepoint - Login failed for User when using Database connection in Owin Startup class
- typescript - TypeScript: Exclude external types from the build output
- c# - Conditional inheritance: base class depend on environment variable
- mysql - How to import a 10GB file to MySQL?
- c++ - 在 cpp 中使用 for_each 循环遍历数组
- google-bigquery - 通过查询从 BigQuery 表中删除一个月数据
- powershell - 运行批处理调用在 CMD 中返回值脚本的 PowerShell。控制台中没有来自 PowerShell 脚本的输出
- r - 使用 DRM 的剂量反应模型错误的 ED50