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" 
}

2 Answers 2

2

Spec

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "description": "=join(', ',@(1,description))"
    }
  }
]
Sign up to request clarification or add additional context in comments.

1 Comment

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}"
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"
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.