https://github.com/artnum/structured-json-query
Convert a JSON object into an SQL where clause or into an LDAP filter.
https://github.com/artnum/structured-json-query
json ldap query-builder query-language sql
Last synced: 18 days ago
JSON representation
Convert a JSON object into an SQL where clause or into an LDAP filter.
- Host: GitHub
- URL: https://github.com/artnum/structured-json-query
- Owner: artnum
- License: mit
- Created: 2024-03-29T09:57:13.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-08T13:42:17.000Z (about 2 years ago)
- Last Synced: 2025-03-14T20:46:11.445Z (about 1 year ago)
- Topics: json, ldap, query-builder, query-language, sql
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Structured JSON Query
Convert a JSON object into an SQL where clause or into an LDAP filter.
## JSON Query Object
### AND, OR
Nesting of fields with AND and OR is possible with the keys #and and #or. This
fields must take an object as a value.
Nesting has no imposed limit on deepness.
### Default operator and type
With no specific type and operator, it will default to equality operator and
string type
```json
{
"#and": {
"name": "John Doe",
"city": "New York"
}
}
```
Result :
* SQL -> name = "John Doe" AND city = "New York"
* LDAP -> (&(name=John Doe)(city=New York))
### Sepcific type and operator
You can specify type and/or operator :
```json
{
"#and": {
"name": {"operator": "~", "type": "str", "value": "Jo*"},
"age": {"operator": ">=", "type": "int", "value": 21}
}
}
```
Result:
* SQL -> name LIKE "Jo%" AND age >= 21
* LDAP -> (&(name=Jo*)(age>=21))
### Nesting example
```json
{
"or": {
"name": {"operator": "~", "value": "J*"},
"#and": {
"age": {"operator": "<", "type": "int", "value": 65},
"age": {"operator": ">", "type": "int", "value": 18}
}
}
}
```
Result :
* SQL -> (name LIKE "J*" OR (age < 65 AND age > 18))
* LDAP -> (|(name=J*)(|(age<65)(age>18)))