Skip to content

Commit bc3c88a

Browse files
committed
add explicit anchors to docs (other basic docs)
1 parent ef12c66 commit bc3c88a

File tree

7 files changed

+51
-36
lines changed

7 files changed

+51
-36
lines changed

json-everything.net/Services/AnchorRegistry.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static async Task RegisterDocs(HttpClient client)
1414
{
1515
await Task.WhenAll(
1616
RegisterAnchors(client, "json-more"),
17+
RegisterAnchors(client, "examples/more/enums"),
1718

1819
RegisterAnchors(client, "json-patch"),
1920

@@ -23,16 +24,22 @@ await Task.WhenAll(
2324

2425
RegisterAnchors(client, "json-logic"),
2526

26-
RegisterAnchors(client, "playground/schema"),
2727
RegisterAnchors(client, "schema-basics"),
28+
RegisterAnchors(client, "examples/schema/external-schemas"),
29+
RegisterAnchors(client, "examples/schema/managing-options"),
30+
RegisterAnchors(client, "examples/schema/version-selection"),
2831
RegisterAnchors(client, "schema-datagen"),
2932
RegisterAnchors(client, "schema-generation"),
33+
RegisterAnchors(client, "examples/schemagen/attribute"),
34+
RegisterAnchors(client, "examples/schemagen/generator"),
35+
RegisterAnchors(client, "examples/schemagen/intent"),
36+
RegisterAnchors(client, "examples/schemagen/refiner"),
3037
RegisterAnchors(client, "schema-vocabs"),
3138
RegisterAnchors(client, "vocabs-data-2022"),
32-
RegisterAnchors(client, "vocabs-unique-keys"),
33-
RegisterAnchors(client, "examples/schema/external-schemas"),
34-
RegisterAnchors(client, "examples/schema/managing-options"),
35-
RegisterAnchors(client, "examples/schema/version-selection")
39+
RegisterAnchors(client, "examples/schemadata/data-ref"),
40+
RegisterAnchors(client, "examples/schemadata/external-ref"),
41+
//RegisterAnchors(client, "examples/schemadata/schema-ref"),
42+
RegisterAnchors(client, "vocabs-unique-keys")
3643
);
3744
}
3845

json-everything.net/wwwroot/md/json-logic.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff 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}
22

33
[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.
44

5-
## The syntax
5+
# The syntax {#logic-syntax}
66

77
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:
88

@@ -19,7 +19,7 @@ So if we want to ensure a value in the input data is less than 2, we could use `
1919

2020
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.
2121

22-
## In code
22+
# In code {#logic-in-code}
2323

2424
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.
2525

@@ -52,11 +52,11 @@ or via `JsonNode.Parse()`.
5252

5353
\* _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._
5454

55-
## Gotchas for .Net developers
55+
# Gotchas for .Net developers {#logic-gotchas}
5656

5757
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.
5858

59-
### `==` vs `===`
59+
## `==` vs `===` {#logic-equality}
6060

6161
`===` defines a "strict" equality. This is the equality we're all familiar with in .Net.
6262

@@ -81,7 +81,7 @@ That _should_ cover everything, but in case something's missed, it'll just retur
8181

8282
\*\* _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._
8383

84-
### Type conversion
84+
## Type conversion {#logic-conversions}
8585

8686
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.
8787

@@ -93,13 +93,13 @@ Because `+` supports both numbers (addition) and strings (concatenation); it wil
9393

9494
Objects are never converted.
9595

96-
### Automatic array flattening
96+
## Automatic array flattening {#logic-array-flattening}
9797

9898
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"]`.
9999

100100
That's it. Not much to it; just be aware that it happens.
101101

102-
## Creating new operators
102+
# Creating new operators {#logic-new-operators}
103103

104104
JSON Logic also supports [adding custom operations](https://jsonlogic.com/add_operation.html).
105105

@@ -120,7 +120,7 @@ It's definitely recommended to go through the [code for the built-in ruleset](ht
120120

121121
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.
122122

123-
## Overriding existing operators
123+
# Overriding existing operators {#logic-overriding}
124124

125125
While this library allows you to inherit from, and therefore override, the default behavior of a `Rule`, you need to be aware of the implications.
126126

json-everything.net/wwwroot/md/json-more.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# Overview {#more}
2+
13
Json.More<nsp>.Net aims to fill gaps left by `System.Text.Json`. To this end, it supplies four additional functions.
24

3-
# Equality comparison
5+
# Equality comparison {#more-equality}
46

57
Sadly, it seems equality was considered unnecessary. To remedy that, the `.IsEquivalentTo()` extension method is supplied for `JsonDocument`, `JsonElement`, and `JsonNode`.
68

@@ -18,7 +20,7 @@ Additionally, an `IEqualityComparer<JsonElement>` is supplied (`JsonElementEqual
1820

1921
***NOTE** Comparers are also supplied for `JsonDocument` and `JsonNode`.*
2022

21-
# Explicitly specifying JSON null with `JsonNode`.
23+
# Explicitly specifying JSON null with `JsonNode` {#more-null}
2224

2325
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.
2426

@@ -28,7 +30,7 @@ Under the covers, it's just a singleton `JsonValue<JsonNull>`. Use `ReferenceEq
2830

2931
***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.*
3032

31-
# Enum serialization
33+
# Enum serialization {#more-enums}
3234

3335
The `EnumStringConverter<T>` class enables string encoding of enum values. `T` is the enum.
3436

@@ -57,9 +59,9 @@ public enum MyFlagsEnum
5759

5860
To use this converter, apply the `[JsonConverter(typeof(EnumStringConverter<T>))]` to either the enum or an enum-valued property.
5961

60-
# Data conversions
62+
# Data conversions {#more-conversion}
6163

62-
## `.AsNode()` extension
64+
## `.AsNode()` extension {#more-asnode}
6365

6466
Previous versions of the libraries in the `json-everything` suite were built on `JsonElement`. They have since been migrated to support `JsonNode` directly.
6567

@@ -71,15 +73,15 @@ JsonNode? node = element.AsNode();
7173

7274
Note that this does potentially return null to handle the JSON null case.
7375

74-
## `.ToJsonArray()` extension
76+
## `.ToJsonArray()` extension {#more-toarray}
7577

7678
.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.
7779

7880
```c#
7981
JsonArray array = new List<JsonNode?>{ 1, null, false }.ToJsonArray();
8082
```
8183

82-
## `.AsJsonElement()` extension
84+
## `.AsJsonElement()` extension {#more-aselement}
8385

8486
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.
8587

@@ -105,7 +107,7 @@ var obj = new Dictionary<string, JsonElement>{
105107
}
106108
```
107109

108-
## Making methods that require `JsonElement` easier to call
110+
## Making methods that require `JsonElement` easier to call {#more-proxy}
109111

110112
***NOTE** If you're using `JsonNode`, you shouldn't need this as it already defines implicit casts from the appropriate types.*
111113

@@ -149,7 +151,7 @@ myObject.SomeMethod("string");
149151

150152
To achieve this without `JsonElementProxy`, you could also create overloads for `short`, `int`, `long`, `float`, `double`, `decimal`, `string`, and `bool`.
151153

152-
# JSON model serialization
154+
# JSON model serialization {#more-serialization}
153155

154156
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.
155157

json-everything.net/wwwroot/md/json-patch.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# Overview {#patch}
2+
13
[JSON Patch](https://tools.ietf.org/html/rfc6902) is a language for modifying JSON documents. Like JSON Schema, it is also expressed in JSON.
24

3-
## Syntax
5+
## Syntax {#patch-syntax}
46

57
A patch consists of an array containing one or more operations. Each operation may also contain one or more arguments.
68

@@ -20,7 +22,7 @@ The arguments vary among them, though all must contain at least an `op` and a `p
2022
- `from` specifies a source location within the JSON document from which to pull a value.
2123
- `value` specifies an explicit value.
2224

23-
## Applying Patches
25+
## Applying Patches {#patch-apply}
2426

2527
In JsonPatch<nsp>.Net, a `JsonPatch` object can be deserialized directly from the JSON document string.
2628

@@ -44,7 +46,7 @@ var myPatchedObject = patch.Apply(myObject);
4446
var myDifferentTypeObject = patch.Apply<MyObject, MyDifferentObject>(myObject);
4547
```
4648

47-
## Inline Patching
49+
## Inline Patching {#patch-inline}
4850

4951
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.
5052

@@ -55,7 +57,7 @@ var patch = new JsonPatch(PatchOperation.Add("/foo/bar", "baz"),
5557

5658
That's it!
5759

58-
## Generating Patches
60+
## Generating Patches {#patch-generation}
5961

6062
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.
6163

json-everything.net/wwwroot/md/json-path.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# Overview {#path}
2+
13
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.
24

35
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).
46

5-
## Syntax
7+
# Syntax {#path-syntax}
68

79
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.
810

@@ -24,7 +26,7 @@ In addition to the above, there are a few shorthand options for some special cas
2426
- `..['foo']` may be rewritten as `..foo`
2527
- `..[*]` may be rewritten as `..*`
2628

27-
### Query Expressions
29+
## Query Expressions {#path-expressions}
2830

2931
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.
3032

@@ -55,7 +57,7 @@ Expressions support the following operations:
5557

5658
_**NOTE** Arithmetic operations are not part of the specification (yet), and cannot be expected to work in other JSON Path implementations._
5759

58-
#### Functions
60+
### Functions {#path-functions}
5961

6062
There is also support for functions within query expressions, which works as an extension point to add your own custom logic.
6163

@@ -70,7 +72,7 @@ The specification defines the following functions:
7072

7173
\* _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._
7274

73-
## In Code
75+
# In Code {#path-in-code}
7476

7577
To obtain an instance of a JSON Path, you'll need to parse it from a string.
7678

@@ -98,7 +100,7 @@ This will return a results object that contains the resulting nodelist or an err
98100

99101
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.
100102

101-
## Adherence to the Proposed Specification
103+
# Adherence to the Proposed Specification {#path-spec}
102104

103105
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.
104106

json-everything.net/wwwroot/md/json-pointer.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# Overview {#pointer}
2+
13
***NOTE** This documentation is based on the the latest non-beta version. Updated documentation is in progress and will be available soon.*
24

35
[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.
46

5-
## The syntax
7+
## Syntax {#pointer-syntax}
68

79
The syntax is really simple:
810

@@ -41,7 +43,7 @@ If a property contains a `/`, it must be escaped by replacing it with `~1`. Add
4143

4244
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 `?`.
4345

44-
## In code
46+
## In code {#pointer-in-code}
4547

4648
The `JsonPointer` class is the model for JSON Pointer.
4749

@@ -78,7 +80,7 @@ var success = pointer.TryEvaluate(element, out var result);
7880

7981
***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.*
8082

81-
## Relative JSON Pointers
83+
## Relative JSON Pointers {#pointer-relative}
8284

8385
[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.
8486

json-everything.net/wwwroot/md/schema-datagen.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generation Sample JSON Data from a Schema {#schema-datagen}
1+
# Generating Sample JSON Data from a Schema {#schema-datagen}
22

33
JsonSchema.Net.DataGeneration is a tool that can create JSON data instances using a JSON schema as a framework.
44

0 commit comments

Comments
 (0)