jq: nested object, extract top-level id and lift a value from internal object

后端 未结 2 1818
醉话见心
醉话见心 2020-12-29 23:20

Given the following xample.json;

[
 {
  \"id\": 12345678,
  \"stuff\": { \"book\": \"shelf\", \"hook\": \"line\", \"took\": \"off\", \"info-spec         


        
2条回答
  •  我在风中等你
    2020-12-30 00:03

    I managed to figure it out.

    $ jq '.[] | { id, "info-spec": .stuff["info-spec"] }' xample.json
    {
      "info-spec": 12,
      "id": 12345678
    }
    {
      "info-spec": 23,
      "id": 12345679
    }
    

    The key here seems to be to use the newkey: .complex["key"] notation for lifting.

提交回复
热议问题