Search code examples
jsonjqstring-concatenation

jq filter to combine two json values into one with a slash delimiter


I'm trying to use jq to process a json input:

{
"foo":"xxx",
"bar":"yyy"
}

Trying to get the following desired json output:

{"path":"xxx/yyy"}

I've tried several things for the filter, generally

.|.foo as $path1|.bar as $path2|{"path":?????}

$path1+"/"+$path2 does not work.

What should I replace ????? with to get desired result?


Solution

  • Or just:

    {"path":(.foo + "/" + .bar)}
    

    or perhaps better (in case conversion to strings is needed):

    {"path": "\(.foo)/\(.bar)"}