Skip to content

Cannot read properties of undefined (reading 'match') on an absent field #218

@Scratch-net

Description

@Scratch-net

Describe the bug

This error gets thrown if match field does not exist

Code sample or steps to reproduce

{
    "items":[
        {
            "name": "John Doe",
            "country": "USA"
        },
        {
          "country": "USA",
          "age":25
        }
    ]
}

//fails
$.items[?(@.name.match(/.*oe/))]

//only way to make it work
$.items[?(@.name && @.name.match(/.*oe/))]

Console error or logs

Error: jsonPath: Cannot read properties of undefined (reading 'match'): @.name.match(/.*abc/)

at JSONPath.Object.<anonymous>.JSONPath._eval
at JSONPath.Object.<anonymous>.JSONPath._walk
at JSONPath.Object.<anonymous>.JSONPath._trace
at JSONPath.Object.<anonymous>.JSONPath._trace
at JSONPath.Object.<anonymous>.JSONPath.evaluate

Expected behavior

no error gets thrown, no results returned

Environment (IMPORTANT)

  • JSONPath-Plus version:v7.2.0

Desktop**

  • NodeJS and browser

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions