combine two jq filters into one

前端 未结 1 978
刺人心
刺人心 2021-01-17 03:19

How jq filter combines the filter outputs? Following jq not generates output.json with respective input arg value (\'jack\').

input.json

{
\"key1\"         


        
相关标签:
1条回答
  • 2021-01-17 03:56

    The filter you are evidently trying to write is:

          if .key1 == "" then . + {"key1" : $input } else . end
          | if .key2 == "" then . + {"key2" : $input } else . end
    

    This can be simplified to:

          if .key1 == "" then .key1 = $input else . end
          | if .key2 == "" then .key2 = $input else . end
    

    You might also like to consider the following approach:

          def update(f): f |= (if . == "" then $input else . end);
          update(.key1) | update(.key2)
    
    0 讨论(0)
提交回复
热议问题