Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referencing data values within a map #124

Open
smf723 opened this issue Feb 10, 2023 · 1 comment
Open

Referencing data values within a map #124

smf723 opened this issue Feb 10, 2023 · 1 comment

Comments

@smf723
Copy link

smf723 commented Feb 10, 2023

This is probably a newbie question and I searched but couldn't find a relevant resolved issue. I have the need to write an expression that references data values outside of the array within a map expression:

Logic:
{
"map": [{ "var": "ROOT.TESTS" },
{ ">=": [{ "var": "RATE" }, { "var": "ROOT.TARGET" }] }
]
}

Data:
{ "ROOT":
{
"TARGET": 23,
"TESTS": [
{ "ID": 1, "RATE": 22 },
{ "ID": 2, "RATE": 23 }
]
}
}

Here I want to find the tests where the test rate value exceeds the target value. Is there any way to reference data values within a map expression that are outside of the data being mapped? Or is there some other approach I could use to accomplish this?

@TotalTechGeek
Copy link

Hey, this currently is not supported in json-logic-js.

I created issue #91 a while back to potentially explore this functionality.

I loathe being a nuisance and shilling for a project that I'm supporting, but json-logic-engine supports this functionality.

Using the logic:

{
    "map": [
        {
            "var": "ROOT.TESTS"
        },
        {
            ">=": [
                {
                    "var": "RATE"
                },
                {
                    "var": "../../ROOT.TARGET"
                }
            ]
        }
    ]
}

And the data you provided, the result computed is [false, true]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants