3

I started with Jolt, but I can't concatenate the elements of the array to single string,

I have json like this:

{
  "partNb": "1234",
  "partDescriptions": [
    {
      "country": "GB",
      "language": "en",
      "content": "1 tool description in en_GB"
    },
    {
      "country": "GB",
      "language": "en",
      "content": "2 tool description in en_GB"
    }
  ]
}

and with jolt spec:

[
  {
    "operation": "shift",
    "spec": {
      "partNb": "id",
      "partDescriptions": {
        "*": {
          "content": "description"
        }
      }
    }
  }
]

For this I have this output:

{
  "id" : "1234",
  "description" : [ "1 tool description in en_GB", "2 tool description in en_GB" ]
}

but how to get result like this?:

{
  "id" : "1234",
  "description" :  "1 tool description in en_GB , 2 tool description in en_GB" 
}
Marek
  • 31
  • 1
  • 2

2 Answers2

2

Spec

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "description": "=join(', ',@(1,description))"
    }
  }
]
Milo S
  • 4,466
  • 1
  • 19
  • 22
  • Thanks for this answer, but the result is : "description" : "{country=GB, language=en, content=1 tool description in en_GB}, {country=GB, language=en, content=2 tool description in en_GB}" – Marek Sep 05 '18 at 06:10
2

To get only content fields concatenated into descriptions:

[
  {
    "operation": "shift",
    "spec": {
      "partDescriptions": {
        "*": {
          "content": {
            "@": "content"
          }
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "description": "=join(', ', @(2,content))"
    }
  }
]

Output:

{
  "content" : [ "1 tool description in en_GB", "2 tool description in en_GB" ],
  "description" : "1 tool description in en_GB, 2 tool description in en_GB"
}

Sergey Shcherbakov
  • 4,534
  • 4
  • 40
  • 65