Code Monkey home page Code Monkey logo

Comments (1)

CacheControl avatar CacheControl commented on May 14, 2024

@skadthan The path feature is provided by selectn under the hood, which as far as I know is the most advanced library around for accessing object paths via string. To my knowledge it doesn't provide the functionality you're looking here, but you may want to take a look in case I'm misremembering.

In terms of solving this for yourself, you could experiment with building a dynamic fact which would give you greater flexibility to traverse the data structure. This is uncharted territory so I can't provide much guidance, but you might be able to get creative.

Finally, make sure the fact data you are feeding into the engine is structured properly - that can certainly make things easier from an access standpoint. So for example, it might make sense to add every element in ObjectA1Array into the engine as its own fact, rather than loading an entire tree in as a single fact and attempting a complex traversal via path. Or taking that a step further, maybe you do some preprocessing to recursively load all the elements contained in the object as an individual fact. Depending on your data and rules this may not be an option, but thought I'd mention it.

In general, the path feature is meant for traversing simple objects, which helps DRY up repetitive rule definitions. Accessing very complex data structures could get tricky to maintain over time, since if the data structure changes in any way, your rules may cease to work. My advice is to find a way to make your facts be simple objects with minimal nesting.

Hope that helps!

from json-rules-engine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.