Skip to content

Commit e9c2e5a

Browse files
docs: update the usage example of the JsonQuery.Net implementation (#3)
1 parent 93895fb commit e9c2e5a

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

src/content/implementations.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,44 @@ Documentation: [https://github.com/lateapexearlyspeed/Lateapexearlyspeed.JsonSch
9393
Install via NuGet:
9494

9595
```text
96-
dotnet add package LateApexEarlySpeed.Json.Schema
96+
dotnet add package JsonQuery.Net
9797
```
9898

9999
Usage:
100100

101-
```dotnet
102-
IJsonQueryable queryable = JsonQueryable.Parse(jsonQuery);
103-
JsonNode? result = queryable.Query(jsonData);
101+
```csharp
102+
using JsonQuery.Net.Queryables;
103+
104+
JsonNode jsonData = JsonNode.Parse("""
105+
{
106+
"friends": [
107+
{ "name": "Chris", "age": 23, "city": "New York" },
108+
{ "name": "Emily", "age": 19, "city": "Atlanta" },
109+
{ "name": "Joe", "age": 32, "city": "New York" },
110+
{ "name": "Kevin", "age": 19, "city": "Atlanta" },
111+
{ "name": "Michelle", "age": 27, "city": "Los Angeles" },
112+
{ "name": "Robert", "age": 45, "city": "Manhattan" },
113+
{ "name": "Sarah", "age": 31, "city": "New York" }
114+
]
115+
}
116+
""")!;
117+
118+
// Get the array containing the friends from the object, filter the friends that live in New York,
119+
// sort them by age, and pick just the name and age out of the objects.
120+
IJsonQueryable jsonQueryable = JsonQueryable.Parse("""
121+
.friends
122+
| filter(.city == "New York")
123+
| sort(.age)
124+
| pick(.name, .age)
125+
""");
126+
127+
JsonNode output = jsonQueryable.Query(jsonData)!;
128+
129+
// output = [
130+
// { "name": "Chris", "age": 23 },
131+
// { "name": "Sarah", "age": 31 },
132+
// { "name": "Joe", "age": 32 }
133+
// ]
104134
```
105135

106136
## How to implement in a new language

0 commit comments

Comments
 (0)