在Linux中解析Json

时间:2012-11-19 10:28:12

标签: json

我需要在linux命令中转换这些数据。任何人都可以帮忙吗?

{"date":"2005\u5e7405\u670812\u65e5(\u6728) 02\u664216\u5206","quiz_no":"1469","body":"\u4e09\u56fd\u5fd7\u3092\u30e2\u30c1\u30fc\u30d5\u306b\u3057\u305f\u6a5f\u7a2e\u3002\u6b63\u3057\u3044\u6a5f\u7a2e\u540d\u306f\u3069\u308c\u304b\uff1f","choice":[{"c1":"CR\u4e09\u56fd\u904a\u622f","c2":"CR\u4e09\u56fd\u904a\u7fa9","c3":"CR\u4e09\u56fd\u6f14\u7fa9"}],"answer":"c2"}

1 个答案:

答案 0 :(得分:1)

您可以使用像underscore这样的工具(基于NodeJS)来美化输出:

echo '{"date":"2005\u5e7405\u670812\u65e5(\u6728) 02\u664216\u5206","quiz_no":"1469","body":"\u4e09\u56fd\u5fd7\u3092\u30e2\u30c1\u30fc\u30d5\u306b\u3057\u305f\u6a5f\u7a2e\u3002\u6b63\u3057\u3044\u6a5f\u7a2e\u540d\u306f\u3069\u308c\u304b\uff1f","choice":[{"c1":"CR\u4e09\u56fd\u904a\u622f","c2":"CR\u4e09\u56fd\u904a\u7fa9","c3":"CR\u4e09\u56fd\u6f14\u7fa9"}],"answer":"c2"}'|underscore pretty

// Result:

{
  date: "2005年05月12日(木) 02時16分",
  quiz_no: "1469",
  body: "三国志をモチーフにした機種。正しい機種名はどれか?",
  choice: [{ c1: "CR三国遊戯", c2: "CR三国遊義", c3: "CR三国演義" }],
  answer: "c2"
}