-2

Can I use JSONPath expressions to get a string out of an array of string?

Example, here is an array of strings:

{
    "objects": [
        "a",
        "b",
        "c"
    ]
}

and the expresion

$.objects[:]

will result into

[
    "a",
    "b",
    "c"
]

however I want to have something like

[
    "a b c"
]

or better

[
    "a, b, c"
]

is this possible?

herrwolken
  • 389
  • 1
  • 4
  • 12

1 Answers1

0

you don't any path, this is enough

var newArray = [oldArray.objects.join(",")];

or if for some reasons you still want jsonPath

var newArray = [jsonPath(oldArray,"$.objects").join(",")];

output

[
    "a, b, c"
]
Serge
  • 40,935
  • 4
  • 18
  • 45