TotalTechGeek / json-logic-engine

Construct complex rules with JSON & process them.
MIT License
43 stars 9 forks source link

Accessing variables in Object with key containing a dot #23

Closed tatarysh closed 7 months ago

tatarysh commented 7 months ago

I encountered an issue related to accessing variables within an object where the key contains a dot. The logical query looks like this:

{
    "var": "hello.world"
}

And the payload is:

{
    "hello": {
        "world": "i'm here!"
    },
    "hello.world": "ups!"
}

Currently, there is no access to the hello.world variable. I believe it would be beneficial to adopt the convention used in the dot-prop package, where access to such a key is possible by including a double backslash before the dot in the key. Therefore, for the mentioned query, it should look like this:

{
    "var": "hello\\.world"
}
TotalTechGeek commented 7 months ago

Hey @tatarysh, I believe I've seen this issue pop up before in the original json-logic-js repo: https://github.com/jwadhams/json-logic-js/issues/127

And semi-related: https://github.com/jwadhams/json-logic-js/issues/110

The suggestion to use the dot-prop convention is a solid recommendation.

I may take a peek into issue 110 from json-logic-js with a bit more intent after merging this in.

TotalTechGeek commented 7 months ago

Hi, I've published 1.3.0 to introduce the escape syntax for paths.

Please let me know if you run into any issues / have any recommendations! (I will need to update the documentation to include this information)

tatarysh commented 7 months ago

great job, thanks 🙏