Skip to content

json.Number format is not supported #27

Open
@shashankmehra

Description

@shashankmehra

If json is Unmarshaled using json.Number format like:

my_map := make(map[string]interface{})
d := json.NewDecoder(strings.NewReader(json_raw))
d.UseNumber()
d.Decode(&my_map)

And then used to search:

var expr1 = jmespath.MustCompile("people[?age > `20`].[name, age]")
result, err := expr1.Search(my_map)

err is nil but the result is [] even though some objects must be returned. Removing the d.UseNumber() makes the Search work properly.

This is probably because this type assertion fails to recognize the value in the map as a Number (float): https://github.com/jmespath/go-jmespath/blob/master/interpreter.go#L48

json.Number is essentially a string. So either reflect/conversion library can be used here or type assertion should handle json.Number.

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