Skip to content

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

@Zatte

Description

@Zatte

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions