jq retain missing array objects from capturing group and update array

前端 未结 3 2057
后悔当初
后悔当初 2021-01-29 03:47

Input

[{
        \"tags\": [{
                \"value\": \"domain:sourcing\"
            },
            {
                  


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-29 04:27

    jq solution:

    jq '{domain: "-", apiname: "-"} as $o 
        | map([.tags[] | .value | split(":") | {(.[0]) : .[1]}] | add | $o + .)' input.json
    
    • {domain: "-", apiname: "-"} as $o - used as a template object

    The output:

    [
      {
        "domain": "sourcing",
        "apiname": "src1"
      },
      {
        "domain": "-",
        "apiname": "fin1"
      },
      {
        "domain": "fin1",
        "apiname": "-"
      }
    ]
    

提交回复
热议问题