mdaverde / jsonpath

jsonpath golang library to help with getting and setting values on paths (even nonexistent paths)
https://pkg.go.dev/github.com/mdaverde/jsonpath
MIT License
22 stars 5 forks source link

feat: adding support to enable custom delimiter #2

Open vishalwithme opened 2 years ago

vishalwithme commented 2 years ago

Hello, Thanks much for the awesome API. It is helping me a lot.

I am sending a feature request to extend the use of delimiter. In my case the required parsed JSON has some of the objects with keys containing same character as default delimiter used (i.e. period/ . ) With this PR end user will be able to set their own delimiter and run queries accordingly. e.g.

jsonpath.SetDelimiter("|") // to set delimiter before use jsonpath.Get(inputJson, "ValuesFiles|metadata|labels|my.label.name")

Also I am a novice in go and apologize if something is wrong with the PR.

Please consider this on urgent basis.

mdaverde commented 2 years ago

Hi @vishalwithme

I plan to grow out the library to include more functionality & configuration options soon. It might make sense to have a more global setOptions() func that is flexible enough to minimize future changes.

Or alternatively, we could consider a constructor (for example, NewJsonpath(opt jsonpathOptions) to initialize custom objects that can be scoped to. Thoughts here?