thedevsaddam / gojsonq

A simple Go package to Query over JSON/YAML/XML/CSV Data
https://github.com/thedevsaddam/gojsonq/wiki
MIT License
2.17k stars 140 forks source link

From should support a variable-length argument to describe the path #58

Open jpap opened 4 years ago

jpap commented 4 years ago

Thanks for a great package! :D

I am parsing JSON that uses a dot (".") for some key names. I've discovered that I could redefine the separator using gojsonq.SetSeparator("·") to a middle-dot, and then use fmt.Sprintf to define the path input to gojsonq.From.

What would be even better would be to avoid all of this, and just have From support multiple arguments, with each argument describing components of the path to the desired node. In this case, the separator can be ignored, and I don't have to use the middle dot setup as above.

For example, q.From("first.level.key.name", "data") would select the path:

where the first path component has dots in it, and the second path component does not.

At the moment, I have to do the following:

q.From(fmt.Sprintf("%s·%s", "first.level.key.name", "data"))
thedevsaddam commented 4 years ago

It seems can be done using fmt.Sprintf so why should we change the existing API?