You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: json-everything.net/wwwroot/md/json-logic.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
*(Not Json<nsp>_Something_<nsp>.Net, sadly. "JsonLogic<nsp>.Net" was already registered on Nuget. It breaks the pattern, I know. _C'est la vie_.)*
1
+
# Overview {#logic}
2
2
3
3
[JsonLogic](https://jsonlogic.com) is a mechanism that can be used to apply logical transformations to JSON values and that is also itself expressed in JSON.
4
4
5
-
##The syntax
5
+
# The syntax {#logic-syntax}
6
6
7
7
JsonLogic is expressed using single-keyed objects called _rules_. The key is the operator and the value is (usually) an array containing the parameters for the operation. Here are a few examples:
8
8
@@ -19,7 +19,7 @@ So if we want to ensure a value in the input data is less than 2, we could use `
19
19
20
20
There are many operators that work on different data types, ranging from string and array manipulation to arithmetic to boolean logic. The full list is [on their website](https://jsonlogic.com/operations.html), and their docs are pretty good, so I won't repeat the list here.
21
21
22
-
##In code
22
+
# In code {#logic-in-code}
23
23
24
24
The library defines an object model for rules, starting with the `Rule` base class. This type is fully serializeable, so if you have rules in a text format, just deserialize them to get a `Rule` instance.
25
25
@@ -52,11 +52,11 @@ or via `JsonNode.Parse()`.
52
52
53
53
\*_JSON null literals need to either be cast to `string`, use `JsonNull.Node` from Json.More.Net, or use the provided `LiteralRule.Null`. All of these result in the same semantic value._
54
54
55
-
##Gotchas for .Net developers
55
+
# Gotchas for .Net developers {#logic-gotchas}
56
56
57
57
In developing this library, I found that many of the operations don't align with similar operations in .Net. Instead they tend to mimic the behavior of Javascript. In this section, I'll try to list some of the more significant ones.
58
58
59
-
###`==` vs `===`
59
+
## `==` vs `===` {#logic-equality}
60
60
61
61
`===` defines a "strict" equality. This is the equality we're all familiar with in .Net.
62
62
@@ -81,7 +81,7 @@ That _should_ cover everything, but in case something's missed, it'll just retur
81
81
82
82
\*\*_These cases effectively mean that the array must have a single element that is loosely equal to the number, though perhaps something like `[1,234]` might pass. Again, the equality is **very** loose._
83
83
84
-
###Type conversion
84
+
## Type conversion {#logic-conversions}
85
85
86
86
Some operations operate on specific types: sometimes strings, sometimes numbers. To ensure maximum support, an attempt will be made to convert values to the type that the operation prefers. If the value cannot be converted, a `JsonLogicException` will be thrown.
87
87
@@ -93,13 +93,13 @@ Because `+` supports both numbers (addition) and strings (concatenation); it wil
Nested arrays are flattened before being operated upon. As an example of this, `[["a"]]` is flattened to `["a"]` and `["a",["b"]]` is flattened to `["a","b"]`.
99
99
100
100
That's it. Not much to it; just be aware that it happens.
101
101
102
-
##Creating new operators
102
+
# Creating new operators {#logic-new-operators}
103
103
104
104
JSON Logic also supports [adding custom operations](https://jsonlogic.com/add_operation.html).
105
105
@@ -120,7 +120,7 @@ It's definitely recommended to go through the [code for the built-in ruleset](ht
120
120
121
121
Once your rule is defined, it needs to be registered using the `RuleRegistry.Register<T>()` method. This will allow the rule to be automatically deserialized.
Copy file name to clipboardExpand all lines: json-everything.net/wwwroot/md/json-more.md
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
+
# Overview {#more}
2
+
1
3
Json.More<nsp>.Net aims to fill gaps left by `System.Text.Json`. To this end, it supplies four additional functions.
2
4
3
-
# Equality comparison
5
+
# Equality comparison {#more-equality}
4
6
5
7
Sadly, it seems equality was considered unnecessary. To remedy that, the `.IsEquivalentTo()` extension method is supplied for `JsonDocument`, `JsonElement`, and `JsonNode`.
6
8
@@ -18,7 +20,7 @@ Additionally, an `IEqualityComparer<JsonElement>` is supplied (`JsonElementEqual
18
20
19
21
***NOTE** Comparers are also supplied for `JsonDocument` and `JsonNode`.*
20
22
21
-
# Explicitly specifying JSON null with `JsonNode`.
23
+
# Explicitly specifying JSON null with `JsonNode` {#more-null}
22
24
23
25
Because `JsonNode` was designed to unify .Net null with JSON null, it's difficult (and sometimes impossible) to determine when a JSON null is explicitly provided vs when it is merely the result of a missing property. Ordinarily (e.g. during deserialization) this isn't much of a problem.
24
26
@@ -28,7 +30,7 @@ Under the covers, it's just a singleton `JsonValue<JsonNull>`. Use `ReferenceEq
28
30
29
31
***IMPORTANT** This is provided exclusively as a signal. It is not intended to be saved. Best practice is to continue to save null. [See the code](https://github.com/gregsdennis/json-everything/blob/595045ec8258f4073ee5666c721609a9c0886490/JsonSchema/ValidationContext.cs#L146-L149) for an example of proper usage.*
30
32
31
-
# Enum serialization
33
+
# Enum serialization {#more-enums}
32
34
33
35
The `EnumStringConverter<T>` class enables string encoding of enum values. `T` is the enum.
34
36
@@ -57,9 +59,9 @@ public enum MyFlagsEnum
57
59
58
60
To use this converter, apply the `[JsonConverter(typeof(EnumStringConverter<T>))]` to either the enum or an enum-valued property.
59
61
60
-
# Data conversions
62
+
# Data conversions {#more-conversion}
61
63
62
-
## `.AsNode()` extension
64
+
## `.AsNode()` extension {#more-asnode}
63
65
64
66
Previous versions of the libraries in the `json-everything` suite were built on `JsonElement`. They have since been migrated to support `JsonNode` directly.
Note that this does potentially return null to handle the JSON null case.
73
75
74
-
## `.ToJsonArray()` extension
76
+
## `.ToJsonArray()` extension {#more-toarray}
75
77
76
78
.Net provided `JsonArray` with a constructor that takes an array of `JsonNode?`, however they don't support converting _any_ enumerable of nodes into an array. This extension will handle that for you.
Sometimes you just want a `JsonElement` that represents a simple value, like a string, boolean, or number. This library exposes several overloads of the `.AsJsonElement()` extension that can do this for you.
85
87
@@ -105,7 +107,7 @@ var obj = new Dictionary<string, JsonElement>{
105
107
}
106
108
```
107
109
108
-
## Making methods that require `JsonElement` easier to call
110
+
## Making methods that require `JsonElement` easier to call {#more-proxy}
109
111
110
112
***NOTE**Ifyou're using `JsonNode`, you shouldn'tneedthisasitalreadydefinesimplicitcastsfromtheappropriatetypes.*
To achieve this without `JsonElementProxy`, you could also create overloads for `short`, `int`, `long`, `float`, `double`, `decimal`, `string`, and `bool`.
151
153
152
-
# JSON model serialization
154
+
# JSON model serialization {#more-serialization}
153
155
154
156
The .Net team did a great job of supporting fast serialization, but for whatever reason they didn't implement serializing their data model. The `Utf8JsonWriterExtensions` class fills that gap.
The `JsonPatch` class can also be built in code using by creating a series of `PatchOperation`s through its static constructor methods. There's one for each operation.
50
52
@@ -55,7 +57,7 @@ var patch = new JsonPatch(PatchOperation.Add("/foo/bar", "baz"),
55
57
56
58
That's it!
57
59
58
-
## Generating Patches
60
+
## Generating Patches {#patch-generation}
59
61
60
62
If you know what your start and end states are, but you want to find the differences, you can do that by generating a patch.
Copy file name to clipboardExpand all lines: json-everything.net/wwwroot/md/json-path.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,10 @@
1
+
# Overview {#path}
2
+
1
3
JSON Path is a query language for JSON documents inspired by what XPath provides for XML documents. It was [originally proposed](https://goessner.net/articles/JsonPath/) by Matt Goessner, and now a [specification](https://github.com/jsonpath-standard/internet-draft) is in progress.
2
4
3
5
Version 0.4.x is aligned with the specification as of the end of Feb 2023, including support for functions (recently merged) and arithmetic operations in expressions (not part of the spec yet).
4
6
5
-
##Syntax
7
+
# Syntax {#path-syntax}
6
8
7
9
A path consists of start indicator followed by a series of segments, chained one after another. Each segment contains one or more selectors. Each selector takes in a collection of JSON nodes and produces a collection of JSON nodes (called a "nodelist") based on their function. The output of the segment is the collective output of all of that segment's selectors. Each segment takes as input the output of the previous selector.
8
10
@@ -24,7 +26,7 @@ In addition to the above, there are a few shorthand options for some special cas
24
26
-`..['foo']` may be rewritten as `..foo`
25
27
-`..[*]` may be rewritten as `..*`
26
28
27
-
###Query Expressions
29
+
## Query Expressions {#path-expressions}
28
30
29
31
Filter selectors take an expression. This expression uses a single variable, which is a JSON node as described above. The node is denoted by `@` and any valid JSON Path can follow it. The `@` is a stand-in for the `$` from above and acts as the root of the local value.
30
32
@@ -55,7 +57,7 @@ Expressions support the following operations:
55
57
56
58
_**NOTE** Arithmetic operations are not part of the specification (yet), and cannot be expected to work in other JSON Path implementations._
57
59
58
-
####Functions
60
+
### Functions {#path-functions}
59
61
60
62
There is also support for functions within query expressions, which works as an extension point to add your own custom logic.
61
63
@@ -70,7 +72,7 @@ The specification defines the following functions:
70
72
71
73
\*_I-Regexp is designed to be an interoperable subset of most popular regular expression specifications and implementations. One difference that [could not be resolved](https://github.com/ietf-wg-jsonpath/iregexp/issues/15) was implicit anchoring. As such, two methods were developed to handle both cases. `match` uses implicit anchoring, while `search` does not._
72
74
73
-
##In Code
75
+
# In Code {#path-in-code}
74
76
75
77
To obtain an instance of a JSON Path, you'll need to parse it from a string.
76
78
@@ -98,7 +100,7 @@ This will return a results object that contains the resulting nodelist or an err
98
100
99
101
A node contains both the value that was found and the location in the instance _where_ it was found. The location is always represented using the "canonical," bracketed format.
100
102
101
-
##Adherence to the Proposed Specification
103
+
# Adherence to the Proposed Specification {#path-spec}
102
104
103
105
As the specification is still under authorship, there are features present in traditional JSON Path that haven't been properly described yet. For these features, this library has been configured to mimic the consensus behaviors of other libraries as determined by the [JSON Path Comparison](https://cburgmer.github.io/json-path-comparison/) project.
Copy file name to clipboardExpand all lines: json-everything.net/wwwroot/md/json-pointer.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,10 @@
1
+
# Overview {#pointer}
2
+
1
3
***NOTE** This documentation is based on the the latest non-beta version. Updated documentation is in progress and will be available soon.*
2
4
3
5
[JSON Pointer](https://tools.ietf.org/html/rfc6901) is a syntax that allows you to isolate a single element within a JSON document by navigating down a series of object properties and array indices.
4
6
5
-
## The syntax
7
+
## Syntax {#pointer-syntax}
6
8
7
9
The syntax is really simple:
8
10
@@ -41,7 +43,7 @@ If a property contains a `/`, it must be escaped by replacing it with `~1`. Add
41
43
42
44
It also supports a URL format, which is essentially the same thing, except that it starts with a `#`, then followed by the standard pointer. This format also will `%`-encode any URL-reserved characters, like `=` and `?`.
43
45
44
-
## In code
46
+
## In code {#pointer-in-code}
45
47
46
48
The `JsonPointer` class is the model for JSON Pointer.
47
49
@@ -78,7 +80,7 @@ var success = pointer.TryEvaluate(element, out var result);
78
80
79
81
***ASIDE** The designers of the `JsonNode` API have elected (for [reasons](https://github.com/dotnet/designs/blob/40794be63ecd8b35e9596412050a84dedd575b99/accepted/2020/serializer/WriteableDomAndDynamic.md#missing-vs-null) I [disagree](https://github.com/dotnet/runtime/issues/66948#issuecomment-1080148457) with) to consider JSON null and .Net null to be equivalent. This goes against both my personal experience building Manatee.Json and the `JsonElement` API, in which these are distinct concepts. Because of this, it is impossible to determine whether a returned `JsonNode` value of `null` represents a value that is present but null or it is merely absent from the data. To accomodate this, the evaluation method can only support the familiar `TryParse()` signature. A return of `true` indicates the value was found, and `false` indicates it was not. In the case of a `true` return, `result` may still be null, indicating the value was found and was a JSON null.*
80
82
81
-
## Relative JSON Pointers
83
+
## Relative JSON Pointers {#pointer-relative}
82
84
83
85
[JSON Hyperschema](https://datatracker.ietf.org/doc/draft-handrews-json-schema-hyperschema/) relies on a variation of JSON Pointers called [Relative JSON Pointers](https://tools.ietf.org/id/draft-handrews-relative-json-pointer-00.html) that also includes the number of parent navigations. This allows the system to start at an internal node in the JSON document and navigate to another node potentially on another subtree.
0 commit comments