Skip to content

Commit

Permalink
📚 docs: update README.md #4
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 12, 2025
1 parent 3ad35dc commit 0a1b22c
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 3 deletions.
98 changes: 96 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,80 @@ Given the `JSON` string
"price_2007": 28.76,
"symbol": "GIS"
}
],
"bank": [
{
"isActive": false,
"balance": "$1,404.23",
"age": 26,
"eyeColor": "blue",
"name": "Stark Jenkins",
"gender": "male",
"company": "HINWAY",
"email": "[email protected]",
"phone": "+1 (943) 542-3591",
"address": "766 Cooke Court, Dunbar, Connecticut, 9512"
},
{
"isActive": false,
"balance": "$1,247.08",
"age": 36,
"eyeColor": "green",
"name": "Odonnell Rollins",
"gender": "male",
"company": "NEXGENE",
"email": "[email protected]",
"phone": "+1 (810) 521-2350",
"address": "210 Pleasant Place, Lloyd, Mississippi, 1636"
},
{
"isActive": false,
"balance": "$2,284.89",
"age": 20,
"eyeColor": "brown",
"name": "Rachelle Chang",
"gender": "female",
"company": "VERAQ",
"email": "[email protected]",
"phone": "+1 (955) 564-2002",
"address": "220 Drew Street, Ventress, Puerto Rico, 8432"
},
{
"isActive": true,
"balance": "$1,624.60",
"age": 39,
"eyeColor": "brown",
"name": "Davis Wade",
"gender": "male",
"company": "ASSISTIX",
"email": "[email protected]",
"phone": "+1 (836) 432-2542",
"address": "532 Amity Street, Yukon, Palau, 3561"
},
{
"isActive": true,
"balance": "$3,818.97",
"age": 23,
"eyeColor": "green",
"name": "Oneill Everett",
"gender": "male",
"company": "INCUBUS",
"email": "[email protected]",
"phone": "+1 (958) 522-2724",
"address": "273 Temple Court, Shelby, Georgia, 8682"
},
{
"isActive": false,
"balance": "$3,243.63",
"age": 21,
"eyeColor": null,
"name": "Dalton Waters",
"gender": "male",
"company": "OVATION",
"email": "[email protected]",
"phone": "+1 (899) 464-3878",
"address": "909 Wyona Street, Adelino, Hawaii, 6449"
}
]
}
```
Expand Down Expand Up @@ -240,8 +314,8 @@ The `#` symbol enables navigation within JSON arrays. To retrieve the length of
### Queries
You can also search an array for the first match by using `#(...)`, or retrieve all matches with `#(...)#`.
Queries support comparison operators such as `==`, `!=`, `<`, `<=`, `>`, `>=`, along with simple pattern matching operators `%` (like) and `!%` (not like).
- You can also search an array for the first match by using `#(...)`, or retrieve all matches with `#(...)#`.
Queries support comparison operators such as `==`, `!=`, `<`, `<=`, `>`, `>=`, along with simple pattern matching operators `%` (like) and `!%` (not like).
```shell
> stock.#(price_2002==56.27).symbol >> "MMM"
Expand All @@ -256,3 +330,23 @@ Queries support comparison operators such as `==`, `!=`, `<`, `<=`, `>`, `>=`, a
> required.#(!%"*s*") >> "taxonId"
> animals.#(foods.likes.#(%"*a*"))#.name >> ["Meowsy","Barky"]
```
- The `~` (tilde) operator evaluates a value as a boolean before performing a comparison.
The most recent value that did not exist is considered `false`.
The supported tilde comparison types are:
```shell
~true Interprets truthy values as true
~false Interprets falsy and undefined values as true
~null Interprets null and undefined values as true
~* Interprets any defined value as true
```
eg.
```shell
> bank.#(isActive==~true)#.name >> ["Davis Wade","Oneill Everett"]
> bank.#(isActive==~false)#.name >> ["Stark Jenkins","Odonnell Rollins","Rachelle Chang","Dalton Waters"]
> bank.#(eyeColor==~null)#.name >> ["Dalton Waters"]
> bank.#(company==~*)#.name >> ["Stark Jenkins","Odonnell Rollins","Rachelle Chang","Davis Wade","Oneill Everett","Dalton Waters"]
```
2 changes: 1 addition & 1 deletion fj.go
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ func (ctx Context) Map() map[string]Context {

// Foreach iterates through the values of a JSON object or array, applying the provided iterator function.
//
// If the `Context` represents a non-existent value (Null or invalid JSON), no iteration occurs.
// If the `Context` represents a non existent value (Null or invalid JSON), no iteration occurs.
// For JSON objects, the iterator receives both the key and value of each item.
// For JSON arrays, the iterator receives only the value of each item.
// If the `Context` is not an array or object, the iterator is called once with the whole value.
Expand Down

0 comments on commit 0a1b22c

Please sign in to comment.