Skip to content

Bug in json_path method for numeric fields #1828

Open
@natenho

Description

@natenho

Expected

root.text_objects = this.json_path("$.body[?(@.type==1)]")

# In:  {"body":[{"type":1,"id":"foo"},{"type":2,"id":"bar"}]}
# Out: {"text_objects":[{"id":"foo","type":1}]}

Reference: https://www.benthos.dev/docs/guides/bloblang/methods/#examples-92

Actual

root.text_objects = this.json_path("$.body[?(@.type==1)]")

# In:  {"body":[{"type":1,"id":"foo"},{"type":2,"id":"bar"}]}
# Out: {"text_objects":[]}

A curious behavior is that when using operators like >, <, >= or <=, the comparison works as expected:

root.text_objects = this.json_path("$.body[?(@.type>1)]")

# In:  {"body":[{"type":1,"id":"foo"},{"type":2,"id":"bar"}]}
# Out: {"text_objects":[{"id":"bar","type":2}]}

So the current workaround for equality is to use >= && <=

root.text_objects = this.json_path("$.body[?(@.type>=1 && @.type<=1)]")

# In:  {"body":[{"type":1,"id":"foo"},{"type":2,"id":"bar"}]}
# Out: {"text_objects":[{"id":"foo","type":1}]}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bloblangBloblang featuresbugwaiting for upstreamBlocked on changes needed in an upstream dependency

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions