yolo007wizard

yolo007wizard

Links

Github: GitHub - dderooy/judge_json at v0.1.1-beta · GitHub
HexDocs: JudgeJson — judge_json v1.1.0

Summary

JudgeJson is an Elixir rule engine where rules are json objects. The judge evaluates a json payload and sees if any rules match.

Rule = condition + action

JudgeJson is storage and action agnostic. Ideally you can store/load rules from a DB and evaluate on incoming json payloads. Handler code can then evaluate rules and action however you like.

Rule engines are great for separating business logic from execution logic.

This was also designed with gui form fills in mind. Longterm I’d like to see if I can get a dynamic phoenix form going to create new rules.

This is a beta release so please let me know if any ideas / improvements. Thanks!

Example

payload

{
    "data": {
        "person": {
            "name": "Lionel",
            "last_name": "Messi",
            "likes": [
                "soccer",
                "hot dogs",
                "sports"
            ]
        }
    },
    "rules": [
        {
            "id": "123456",
            "conditions": {
                "all": [
                    {
                        "path": "/person/name",
                        "operator": "equal",
                        "value": "Lionel"
                    },
                    {
                        "path": "/person/last_name",
                        "operator": "equal",
                        "value": "Messi"
                    },
                    {
                        "path": "/person/likes",
                        "operator": "contains",
                        "value": "soccer"
                    }
                ]
            },
            "action": "collect_signature.exs"
        }
    ]
}
iex> JudgeJson.evaluate(payload)

Returns a list of matched rules

Showing Posts 1 to 4

dimitarvp

dimitarvp

Your example is not bad but can you give us a more complete example of what is this code achieving in a real business project?

codeanpeace

codeanpeace

Funnily enough, there’s a long history of rules engines used in the business world – probably why it’s often known as a business rules engine!

In addition to the examples above, there’s

  • targeted advertising based on user demographics
  • clinical recommendations/alerts based on patient information
  • awarding badges based on user activity e.g. discourse, stack overflow
yolo007wizard

yolo007wizard OP

Yea rule engines have various purposes. I’ll admit they are probably overkill / out of scope for most hobby projects. At my work we have an in house engine that reacts to security alerts and its now the secret sauce of the biz.

A general design pattern:

  • collect / observe incoming data
  • evaluate against rules for any matches
  • trigger reactionary actions

Imo they fit really well with event hooks, event handling, and ETL flows. Generic webhook endpoint → rule match some condition → route / handle payload.

The main benefits:
You can change your business logic on the fly during runtime. Essentially hot swap your business logic without reloading an app or changing code. It also makes changes much more maintainable with faster turn around time.

Another understated benefit; you can isolate team and company concerns. One team / group can manage business rule CRUD lifecycle while another specialized dev team manages execution logic (action flows etc). This is a huge benefit imo - none coders can create new rules through a form gui and quickly change automation flows. Slap on some manager audit process for new rules and you have a self-serve process with no more Jira tickets for your dev team :wink:

Morotai

Morotai

Late to this party but have a need for a rule engine for my project and wondering if going this way has advantages over adding users to a database table. I have two use cases:

  1. Determine if each user has been given/assigned a golden ticket (today we keep in PostgreSQL db table: userId=user1, hasticket=true or false, Isregistered=true or false, date=datetime)
  2. Rule based scenario:
    Condition: If user1 is from department1 (we get from the user property) and has golden ticket,
    Action: Send congrats email and ask to register for factory tour.

Just wondering if it would be best to use the same rule engine like (judge_json) to do both or just keep it as simple DB query?

Thanks!

— All posts loaded —

Where Next? Top

Trending in Announcing Top

type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews