Skip to content

Grouping doesn't apply as expected when filtering #312

@daanp

Description

@daanp

Apologies in advance if overlooking something obvious - I am not well versed in JSONata

I'm trying to reproduce this case with the library: https://try.jsonata.org/ZkhsVPArq

It seems that there is something weird happening when applying a grouping after a filter. An example can be found in the test below:

    @Test
    void testBrokenPredicate() throws Exception {
        JSONObject json = new JSONObject("{\"vendor\":[{\"name\":\"kwik\",\"number\":1},{\"name\":\"kwek\",\"number\":2},{\"name\":\"kwak\",\"number\":3},{\"name\":\"kwak\",\"number\":4}]}");

        @Nonnull final JsonNode jsonObj;
        try {
            jsonObj = new ObjectMapper().readTree(json.toString());
        } catch (IOException e) {
            throw new APIException(e, "JSONata failed during reading of json");
        }
        Expressions jsonataExpression = Expressions.parse("vendor[name=\"kwak\"]{`name`: `number`}");
        Expressions brokenJsonataExpression = Expressions.parse("vendor[name=\"kwek\"]{`name`: `number`}");

        JsonNode result = jsonataExpression.evaluate(jsonObj);
        JsonNode brokenResult = brokenJsonataExpression.evaluate(jsonObj);

        // The brokenResult does not apply the grouping as expected
        JSONAssert.assertEquals("{\"kwak\":[3,4]}", result.toString(), true);

        // Here we can see the actual result
        JSONAssert.assertEquals("{\"kwek\":{\"number\":2,\"name\":\"kwek\"}}", brokenResult.toString(), true);

        // I expect this to succeed as seen here https://try.jsonata.org/ZkhsVPArq, but it fails
        JSONAssert.assertEquals("{\"kwek\":2}", brokenResult.toString(), true);
    }

Please let me know what I'm doing wrong or if this is a known issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy