Skip to content

JSON-Criteria is a JSON document describing criteria, a tree of boolean expressions. These can be used to evaluate against context data.

License

Notifications You must be signed in to change notification settings

fre-sch/json-criteria

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

JSON-Criteria

JSON-Criteria is a JSON document describing criteria, a tree of boolean expressions. These can be used to evaluate against context data.

Implementations provide access to context data via any string. This document recommends using JSON-Path.

Operators

#equals

let expression = {
    "#equals": {
        "$.person.firstname": "Bob"
    }
}
let context = {
    "person": {
        "firstname": "Alice"
    }
}
JSONCriteria(expression, context) === false
let expression = {
    "#equals": {
        "$.person.firstname": "alice",
        "#caseIgnore": true
    }
}
let context = {
    "person": {
        "firstname": "Alice"
    }
}
JSONCriteria(expression, context) === false

#regex

let expression = {
    "#regex": {
        "$.person.firstname": "bob|alice",
        "#caseIgnore": true
    }
}
let context = {
    "person": {
        "firstname": "Alice"
    }
}
JSONCriteria(expression, context) === true

#and

Equivalent to (chaining) and expressions, for example in JavaScript expr && expr && expr. Each array item must be a valid JSON-Criteria expression.

let expression = {
    "#and": [
        {
            "$.person.firstname": "Alice"
        }
    ]
}
let context = {
    "person": {
        "firstname": "Alice"
    }
}
JSONCriteria(expression, context) === true
let expression = {
    "#and": [
        {
            "$.person.firstname": "Alice"
        },
        {
            "$.person.lastname": "Example"
        }
    ]
}
let context = {
    "person": {
        "firstname": "Alice",
        "lastname": "Tester",
    }
}
JSONCriteria(expression, context) === false

#or

Equivalent to (chaining) or expressions, for example in JavaScript expr || expr || expr. Each array item must be a valid JSON-Criteria expression.

let expression = {
    "#or": [
        {
            "$.person.firstname": "Alice"
        }
    ]
}
let context = {
    "person": {
        "firstname": "Alice"
    }
}
JSONCriteria(expression, context) === true
let expression = {
    "#or": [
        {
            "$.person.firstname": "Alice"
        },
        {
            "$.person.lastname": "Example"
        }
    ]
}
let context = {
    "person": {
        "firstname": "Alice",
        "lastname": "Tester",
    }
}
JSONCriteria(expression, context) === true

#not

let expression = {
    "#not": true
}
let context = {
    "person": {
        "firstname": "Alice"
    }
}
JSONCriteria(expression, context) === false
let expression = {
    "#not": false
}
let context = {
    "person": {
        "firstname": "Alice"
    }
}
JSONCriteria(expression, context) === true
let expression = {
    "#not": {
        "#equals": {
            "$.person.firstname": "Alice"
        }
    }
}
let context = {
    "person": {
        "firstname": "Alice"
    }
}
JSONCriteria(expression, context) === false

About

JSON-Criteria is a JSON document describing criteria, a tree of boolean expressions. These can be used to evaluate against context data.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published