Omitting null values for sub() in JQ Omitting null values for sub() in JQ json json

Omitting null values for sub() in JQ


You were close. To retain the original structure, you need to use the update operator (|=) instead of pipe. Enclosing the entire expression to the left of it in parentheses is also necessary, otherwise the original input will be invisible to |=.

(.results[].suites[].tests[].context | strings) |= sub("#"; "%23")

Online demo


change # to %23 in every context value

You might wish to consider:

walk( if type=="object" and (.context|type)=="string"      then .context |= gsub("#"; "%23")      else . end )