Skip to content

Single-Level vs Multi-Level Wildcard produces unexpected result on Predicate #70

Description

@JohnBehnke

Hello!

I've encountered what I believe could be a bug when evaluating some JSONata:

I have the following JSON:

[
  {
    "value": {
      "Name": "Cell1",
      "Product": "Product1"
    }
  },
  {
    "value": {
      "Name": "Cell2",
      "Product": "Product2"
    }
  }
]

I am attempting to run the following JSONata expression against it:

*[value.Product = 'Product1']

I expect the result to be

{
  "value": {
    "Name": "Cell1",
    "Product": "Product1"
  }
}

But instead I receive null.

Changing the expression to the following does produce the correct response.

**[value.Product = 'Product1']

I've verified that I do receive that expected bit of JSON on https://try.jsonata.org/.

This is what my code looks like:

import static com.dashjoin.jsonata.Jsonata.jsonata;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {

    public static void main(String[] args) throws Throwable {

        String json = "[\n" +
                "  {\n" +
                "    \"value\": {\n" +
                "      \"Name\": \"Cell1\",\n" +
                "      \"Product\": \"Product1\"\n" +
                "    }\n" +
                "  },\n" +
                "  {\n" +
                "    \"value\": {\n" +
                "      \"Name\": \"Cell2\",\n" +
                "      \"Product\": \"Product2\"\n" +
                "    }\n" +
                "  }\n" +
                "]";

        var data = new ObjectMapper().readValue(json, Object.class);

        var expression = jsonata("*[value.Product = 'Product1']");
        var result = expression.evaluate(data);  // Expecting the first object in the array, but get null instead

        var expression2 = jsonata("**[value.Product = 'Product1']");
        var result2 = expression2.evaluate(data);  // Received the first object in the array as expected
    }
}

I apologize if this isn't the right avenue or format for a bug report, or if there is something trivial that I've missed.

Thank you in advance for any help/guidance :)

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions