javascriptjsonpathjsonpath-plus

Why does JSON parsing with jsonpath-plus throw a TypeError?


When my code calls jsonpath-plus, it's getting TypeError: Cannot read property 'value' of null (where value is the name of a child that I want to check). This occurs whenever the object provided in the `json' parameter has a null property. My path includes a conditional selector:

JSONPath({json: {content: null}, path: "$..[?(@.value)]"}

This is a simple case that always causes TypeError to be thrown.


Solution

  • This is a changed behavior introduced in jsonpath-plus version 5.0.4 around April 1, 2021. In verions 5.0.2 & 5.0.3, the conditional selector simply does not match the object. This appears to be a breaking change, so one would hope it will be reverted back in the next patch release. In the mean time, I'm using 5.0.3.

    The maintainer has indicated that the breaking change is a bug-fix, so it's unlikely that the change will be reverted.