Skip to content

Filter expression literals and membership operators #62

Closed

Description

@jg-rp

We're getting a JSONPathSyntaxError when testing arrays for membership with filter expression literals.

PR #60 correctly introduced checks forcing literals to be compared, but failed to account for our non-standard in and contains operators.

This example should return one JSON value (the second book), but currently raises a syntax error.

import json
import jsonpath

books = [
    {
        "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby Dick",
        "isbn": "0-553-21311-3",
        "price": 8.99,
    },
    {
        "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99,
        "edition": {
            "publish_date": "1987",
            "publisher": "Houghton Mifflin Company",
            "language": "English",
        },
        "places": [
            "Mordor",
            "Hornburg",
            "Isengard",
            "Cracks of Doom",
            "Fangorn Forest",
            "Middle Earth",
            "Tierra Media",
        ],
    },
]

rv = jsonpath.findall(
    "$[[email protected] contains 'Mordor' && @.places contains 'Isengard']",
    books,
)

print(json.dumps(rv, indent=4))

Activity

  1. added
    bug
    on Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions