From d598e20e36c342c9543aaa4705c99ec12e1133fe Mon Sep 17 00:00:00 2001 From: Brenton Farmer Date: Mon, 25 Nov 2024 06:41:44 -0800 Subject: [PATCH] updates --- README.md | 2 +- docs/additional-classes.md | 44 +++++++++---------- docs/jsonpath/syntax.md | 10 ++--- src/Hyperbee.Json/Hyperbee.Json.csproj | 3 +- src/Hyperbee.Json/Patch/JsonDiff.cs | 6 +-- src/Hyperbee.Json/Patch/JsonPatch.cs | 9 ++-- src/Hyperbee.Json/Path/JsonPath.cs | 8 ++-- .../Hyperbee.Json.Cts.csproj | 2 +- .../Hyperbee.Json.Tests.csproj | 2 +- 9 files changed, 44 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index a22080e..f857c05 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ choice for pinpointing exact values. Hyperbee.Json's JsonPointer implementation ## JSONPatch JSONPatch is a format for describing changes to a JSON document. It allows you to apply partial modifications to JSON data efficiently. -Hyperbee.Json supports JsonPatch as defined in [RFC 6902](https://www.rfc-editor.org/rfc/rfc6902.html), ensuring compatibility and reliability. +Hyperbee.Json supports JsonPatch as defined in [RFC 6902](https://www.rfc-editor.org/rfc/rfc6902.html). [Read more about JsonPatch](https://stillpoint-software.github.io/hyperbee.json/jsonpatch.html) diff --git a/docs/additional-classes.md b/docs/additional-classes.md index 232a3fa..c50034c 100644 --- a/docs/additional-classes.md +++ b/docs/additional-classes.md @@ -4,59 +4,59 @@ title: Additional Classes nav_order: 99 --- -## Additional Classes +# Additional Classes In addition to JSONPath, a few additional classes are provided to support pointer-style property diving, element comparisons, and dynamic property access. -### JsonNodeFactory +## JsonNodeFactory The JsonNodeFactory efficiently converts a `JsonElement` to a `JsonNode` with minimal memory allocation. This method performs substantially better than the common serialize deserialize, or parse raw string techniques. -| Class | Description -|:---------------------------|:----------- -| `JsonNodeFactory` | Efficiently convert a `JsonElement` to a `JsonNode` +| Class | Description +|:----------------------------------|:----------- +| `JsonNodeFactory` | Efficiently convert a `JsonElement` to a `JsonNode` -### JsonPath Pointer +## JsonPath Pointer JsonPathPointer acts **similarly** to JSON Pointer; it expects an absolute path that returns a single element. Unlike JSON Pointer, property diving notation expects normalized JSON Path notation. -| Class | Description -|:-----------------------------------|:----------- -| `JsonPathPointer` | Dives for properties using absolute locations like `$.store.book[2].author` +| Class | Description +|:----------------------------------|:----------- +| `JsonPathPointer` | Dives for properties using absolute locations like `$.store.book[2].author` The syntax supports absolute (normalized) paths; dotted notation, quoted names, and simple bracketed array accessors only. The intention is to return a single element by literal path. Json path style wildcard '*', '..', and '[a,b]' multi-result selector notations and filters are **not** supported. -### JsonElement Path +## JsonElement Path Unlike `JsonNode`, `JsonElement` does not have a `Path` property. `JsonPathBuilder` will find the path for a given `JsonElement`. -| Class | Description -|:---------------------------|:----------- -| `JsonPathBuilder` | Returns the JsonPath location string for a given element +| Class | Description +|:----------------------------------|:----------- +| `JsonPathBuilder` | Returns the JsonPath location string for a given element -### Equality Helpers +## Equality Helpers -| Method | Description -|:-----------------------------------|:----------- -| `JsonElement.DeepEquals` | Performs a deep equals comparison on two `JsonElements` -| `JsonElementDeepEqualityComparer` | A deep equals equality comparer that compares two `JsonElements` +| Method | Description +|:----------------------------------|:----------- +| `JsonElement.DeepEquals` | Performs a deep equals comparison on two `JsonElements` +| `JsonElementDeepEqualityComparer` | A deep equals equality comparer that compares two `JsonElements` -### Dynamic Object Serialization +## Dynamic Object Serialization Basic support is provided for serializing to and from dynamic objects through the use of a custom `JsonConverter`. The `DynamicJsonConverter` class is useful for simple scenareos. It is intended as a simple helper for basic use cases only. A helper methods `JsonHelper.ConvertToDynamic` is provided to simplify the process of serializing and deserializing dynamic objects. -#### Example: ConvertToDynamic +### Example: Convert To Dynamic ```csharp var root = JsonDocument.Parse(jsonInput); // jsonInput contains the bookstore example @@ -70,7 +70,7 @@ Assert.IsTrue( price == 8.95 ); Assert.IsTrue( author == "Nigel Rees" ); ``` -#### Example: Serialize To Dynamic +### Example: Serialize To Dynamic ```csharp var serializerOptions = new JsonSerializerOptions @@ -88,7 +88,7 @@ var jsonOutput = JsonSerializer.Serialize( jobject, serializerOptions ) Assert.IsTrue( jsonInput == jsonOutput ); ``` -##### Enum handling +#### Enum handling When deserializing, the converter will treat enumerations as strings. You can override this behavior by setting the `TryReadValueHandler` on the converter. This handler will allow you to intercept and convert string and diff --git a/docs/jsonpath/syntax.md b/docs/jsonpath/syntax.md index d7041e6..ea7d8ec 100644 --- a/docs/jsonpath/syntax.md +++ b/docs/jsonpath/syntax.md @@ -22,7 +22,7 @@ JSONPath operates on JSON documents: ### JSONPath Syntax | JSONPath | Description -|:---------------------------------------------|:----------------------------------------------------------- +|:---------------------------------------------|:------------------------------------------- | `$` | Root JSON node | `@` | Current JSON node | `.`, `.''`, or `.""` | Object member dot operator @@ -38,10 +38,10 @@ JSONPath operates on JSON documents: The library extends the JSONPath expression syntax to support additional features. -| Operators | Description | Example -|---------------------|-----------------------------------------------|------------------------------------------------ -| `+` `-` `*` `\` `%` | Basic math operators. | `$[?(@.a + @.b == 3)]` -| `in` | Tests is a value is in a set. | `$[?@.value in ['a', 'b', 'c'] ]` +| Operators | Description | Example +|---------------------|---------------------------------|---------------------------------- +| `+` `-` `*` `\` `%` | Basic math operators. | `$[?(@.a + @.b == 3)]` +| `in` | Tests is a value is in a set. | `$[?@.value in ['a', 'b', 'c'] ]` ## JSONPath Operators diff --git a/src/Hyperbee.Json/Hyperbee.Json.csproj b/src/Hyperbee.Json/Hyperbee.Json.csproj index 44b2f39..d4e95be 100644 --- a/src/Hyperbee.Json/Hyperbee.Json.csproj +++ b/src/Hyperbee.Json/Hyperbee.Json.csproj @@ -1,6 +1,6 @@  - net9.0 + net8.0;net9.0 enable true @@ -9,7 +9,6 @@ json-path;jsonpath;json-pointer;jsonpointer;json-patch;jsonpatch;query;path;patch;diff;json;rfc9535;rfc6901;rfc6902 icon.png https://stillpoint-software.github.io/hyperbee.json/ - net9.0 LICENSE Stillpoint Software, Inc. Hyperbee Json diff --git a/src/Hyperbee.Json/Patch/JsonDiff.cs b/src/Hyperbee.Json/Patch/JsonDiff.cs index e46f996..5664c8f 100644 --- a/src/Hyperbee.Json/Patch/JsonDiff.cs +++ b/src/Hyperbee.Json/Patch/JsonDiff.cs @@ -140,7 +140,7 @@ private static void ProcessArrayDiff( DiffOperation operation, Stack 0 || col > 0 ) { @@ -177,7 +177,7 @@ private static void ProcessArrayDiff( DiffOperation operation, Stack node, + JsonNode node => node.DeepClone(), + _ => JsonValue.Create( patch.Value ) + }; } public IEnumerator GetEnumerator() diff --git a/src/Hyperbee.Json/Path/JsonPath.cs b/src/Hyperbee.Json/Path/JsonPath.cs index 8108d74..3e32f11 100644 --- a/src/Hyperbee.Json/Path/JsonPath.cs +++ b/src/Hyperbee.Json/Path/JsonPath.cs @@ -116,11 +116,11 @@ private static IEnumerable EnumerateMatches( TNode root, NodeArgs args, N var (parent, value, key, segmentNext, flags) = args; -// call node processor if it exists and the `key` is not null. -// the key is null when a descent has re-pushed the descent target. -// this should be safe to skip; we will see its values later. + ProcessArgs: + // call node processor if it exists and the `key` is not null. + // the key is null when a descent has re-pushed the descent target. + // this should be safe to skip; we will see its values later. -ProcessArgs: if ( key != null ) processor?.Invoke( parent, value, key, segmentNext ); diff --git a/test/Hyperbee.Json.Cts/Hyperbee.Json.Cts.csproj b/test/Hyperbee.Json.Cts/Hyperbee.Json.Cts.csproj index 0e59954..46d73c4 100644 --- a/test/Hyperbee.Json.Cts/Hyperbee.Json.Cts.csproj +++ b/test/Hyperbee.Json.Cts/Hyperbee.Json.Cts.csproj @@ -1,7 +1,7 @@ - net9.0 + net9.0 enable enable diff --git a/test/Hyperbee.Json.Tests/Hyperbee.Json.Tests.csproj b/test/Hyperbee.Json.Tests/Hyperbee.Json.Tests.csproj index 7dd8868..574ad03 100644 --- a/test/Hyperbee.Json.Tests/Hyperbee.Json.Tests.csproj +++ b/test/Hyperbee.Json.Tests/Hyperbee.Json.Tests.csproj @@ -1,6 +1,6 @@  - net9.0 + net8.0;net9.0 false Hyperbee.Json.Tests