Skip to content

Unexpected error when using the $lookup function #328

@PhoeniXPlayDEV

Description

@PhoeniXPlayDEV

Sample code for reproducing the error:

package com.example;

import com.api.jsonata4java.expressions.EvaluateException;
import com.api.jsonata4java.expressions.Expressions;
import com.api.jsonata4java.expressions.ParseException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class JSONataExample {
    public static void main(String[] args) {
        String json = """
        {
          "company": {
            "name": "TechCorp",
            "departments": {
              "IT": { "employees": 50 },
              "HR": { "employees": 10 }
            }
          }
        }
        """;

        final var expression = """
            $map($keys($.company.departments), function($k) {
                  [ $.company.name, $k, $lookup($.company.departments, $k).employees ]
                })
            """;

        final var mapper = new ObjectMapper();
        try {
            final var input = mapper.readTree(json);
            var expr = Expressions.parse(expression);
            try {
                final var result = expr.evaluate(input);
                System.out.println("JSONata result: " + result);
            } catch (EvaluateException e) {
                System.err.println(e.getLocalizedMessage());
            }
        } catch (IOException | ParseException  e) {
            e.printStackTrace();
        }
    }
}

Output:

Argument 2 of function $lookup does not match function signature

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions