【问题标题】:Using sed to get an exact value from a JSON response使用 sed 从 JSON 响应中获取准确值
【发布时间】:2019-11-02 17:29:57
【问题描述】:

我从curl 命令获取这个字符串数据

 {"password": [["passwordreal", "2035/01/01 00:00"]], "user": "user1", "address": "kobebkokoko.net"}

如何使用sed 获得passwordreal

例如,

curl xxxx | sed -n '/ *"password"' => Been working on this long hours.

【问题讨论】:

  • “如何从 JSON 字符串中提取 JSON 值”的简短回答是“不使用 sed — 使用 jq,除非您有自己喜欢的替代 JSON 操纵器程序”。好的,所以它不是很短,但它是重点。

标签: json unix curl sed jq


【解决方案1】:

用jq:

| jq -r '.password[]|.[0]'

输出:

密码真实

使用可以安全处理 JSON 的工具。 sed 不是其中之一。

【讨论】:

  • 如何修剪“”?获取"passwordreal"
  • 如果你想要 "passwordreal" 删除 -r
  • 或者简称.password[][0],或者可能真正想要的是:.password[0][0]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-05
相关资源
最近更新 更多