tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
14.39k stars 857 forks source link

join flat array to comma separated string #336

Closed coolibre closed 10 months ago

coolibre commented 1 year ago
{
  "name": {"first": "Tom", "last": "Anderson"},
  "age":37,
  "children": ["Sara","Alex","Jack"],
  "fav.movie": "Deer Hunter",
  "friends": [
    {"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
    {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
    {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
  ]
}

Is it possible to achieve

"Sara, Alex, Jack"

with a gjson query?

volans- commented 1 year ago

@coolibre I don't think it's possible with the standard features but you can surely write a simple modifier to do that fairly quickly. See https://github.com/tidwall/gjson/blob/master/SYNTAX.md#custom-modifiers for more details on custom modifiers.

coolibre commented 1 year ago

Thank you very much @volans- ! Unfortunately I'm coming from a Telegraf config who use the gjson parser as basis for their json_v2 plugin. I cannot use custom modifiers over there. I was hoping for a standard feature. So I have to stick to their xpath_json parser which seems to have such a function but is not so handy.

Maybe this could be used as a feature request for a standard modifier. If not this issue can be closed!