Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for [(@.length-1)] #34

Open
Zatte opened this issue Mar 26, 2023 · 0 comments
Open

Support for [(@.length-1)] #34

Zatte opened this issue Mar 26, 2023 · 0 comments

Comments

@Zatte
Copy link

Zatte commented Mar 26, 2023

Hi,

How would one go about to get support for the [@.length - n] syntax illustrated @ https://goessner.net/articles/JsonPath/

I know that [start:stop] using negative indices is an ok workaround if we have control over the input. Given that gval and jsonpath is meant for end-users to input business logic it would be nice to expose full jsonpath engine and not jsonpath minus some features.

	v := interface{}(nil)
	json.Unmarshal([]byte(`{
		"welcome":{
				"message":["Good Morning", "Hello World!"]
			}
		}`), &v)
	welcome, err := jsonpath.Get("$.welcome.message[(@.length -1)]", v)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println(welcome)

https://go.dev/play/p/tDVmCrg6_OJ

=>

parsing error: $.welcome.message[(@.length -1)]	:1:29 - 1:30 unexpected "-" while scanning parentheses expected ")"

PS. Awesome work with both gval and jsonpath; Amazing libraries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant