Skip to content

Commit d598e20

Browse files
committed
updates
1 parent 5beb8d4 commit d598e20

9 files changed

Lines changed: 44 additions & 42 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ choice for pinpointing exact values. Hyperbee.Json's JsonPointer implementation
3232
## JSONPatch
3333

3434
JSONPatch is a format for describing changes to a JSON document. It allows you to apply partial modifications to JSON data efficiently.
35-
Hyperbee.Json supports JsonPatch as defined in [RFC 6902](https://www.rfc-editor.org/rfc/rfc6902.html), ensuring compatibility and reliability.
35+
Hyperbee.Json supports JsonPatch as defined in [RFC 6902](https://www.rfc-editor.org/rfc/rfc6902.html).
3636

3737
[Read more about JsonPatch](https://stillpoint-software.github.io/hyperbee.json/jsonpatch.html)
3838

docs/additional-classes.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,59 @@ title: Additional Classes
44
nav_order: 99
55
---
66

7-
## Additional Classes
7+
# Additional Classes
88

99
In addition to JSONPath, a few additional classes are provided to support pointer-style
1010
property diving, element comparisons, and dynamic property access.
1111

12-
### JsonNodeFactory
12+
## JsonNodeFactory
1313

1414
The JsonNodeFactory efficiently converts a `JsonElement` to a `JsonNode` with minimal memory allocation. This
1515
method performs substantially better than the common serialize deserialize, or parse raw string techniques.
1616

17-
| Class | Description
18-
|:---------------------------|:-----------
19-
| `JsonNodeFactory` | Efficiently convert a `JsonElement` to a `JsonNode`
17+
| Class | Description
18+
|:----------------------------------|:-----------
19+
| `JsonNodeFactory` | Efficiently convert a `JsonElement` to a `JsonNode`
2020

2121

22-
### JsonPath Pointer
22+
## JsonPath Pointer
2323

2424
JsonPathPointer acts **similarly** to JSON Pointer; it expects an absolute path that returns a single element.
2525
Unlike JSON Pointer, property diving notation expects normalized JSON Path notation.
2626

27-
| Class | Description
28-
|:-----------------------------------|:-----------
29-
| `JsonPathPointer<JsonElement>` | Dives for properties using absolute locations like `$.store.book[2].author`
27+
| Class | Description
28+
|:----------------------------------|:-----------
29+
| `JsonPathPointer<JsonElement>` | Dives for properties using absolute locations like `$.store.book[2].author`
3030

3131
The syntax supports absolute (normalized) paths; dotted notation, quoted names, and simple bracketed array accessors only.
3232
The intention is to return a single element by literal path.
3333

3434
Json path style wildcard '*', '..', and '[a,b]' multi-result selector notations and filters are **not** supported.
3535

36-
### JsonElement Path
36+
## JsonElement Path
3737

3838
Unlike `JsonNode`, `JsonElement` does not have a `Path` property. `JsonPathBuilder` will find the path
3939
for a given `JsonElement`.
4040

41-
| Class | Description
42-
|:---------------------------|:-----------
43-
| `JsonPathBuilder` | Returns the JsonPath location string for a given element
41+
| Class | Description
42+
|:----------------------------------|:-----------
43+
| `JsonPathBuilder` | Returns the JsonPath location string for a given element
4444

45-
### Equality Helpers
45+
## Equality Helpers
4646

47-
| Method | Description
48-
|:-----------------------------------|:-----------
49-
| `JsonElement.DeepEquals` | Performs a deep equals comparison on two `JsonElements`
50-
| `JsonElementDeepEqualityComparer` | A deep equals equality comparer that compares two `JsonElements`
47+
| Method | Description
48+
|:----------------------------------|:-----------
49+
| `JsonElement.DeepEquals` | Performs a deep equals comparison on two `JsonElements`
50+
| `JsonElementDeepEqualityComparer` | A deep equals equality comparer that compares two `JsonElements`
5151

52-
### Dynamic Object Serialization
52+
## Dynamic Object Serialization
5353

5454
Basic support is provided for serializing to and from dynamic objects through the use of a custom `JsonConverter`.
5555
The `DynamicJsonConverter` class is useful for simple scenareos. It is intended as a simple helper for
5656
basic use cases only. A helper methods `JsonHelper.ConvertToDynamic` is provided to simplify the process of
5757
serializing and deserializing dynamic objects.
5858

59-
#### Example: ConvertToDynamic
59+
### Example: Convert To Dynamic
6060

6161
```csharp
6262
var root = JsonDocument.Parse(jsonInput); // jsonInput contains the bookstore example
@@ -70,7 +70,7 @@ Assert.IsTrue( price == 8.95 );
7070
Assert.IsTrue( author == "Nigel Rees" );
7171
```
7272

73-
#### Example: Serialize To Dynamic
73+
### Example: Serialize To Dynamic
7474

7575
```csharp
7676
var serializerOptions = new JsonSerializerOptions
@@ -88,7 +88,7 @@ var jsonOutput = JsonSerializer.Serialize<dynamic>( jobject, serializerOptions )
8888
Assert.IsTrue( jsonInput == jsonOutput );
8989
```
9090

91-
##### Enum handling
91+
#### Enum handling
9292

9393
When deserializing, the converter will treat enumerations as strings. You can override this behavior by setting
9494
the `TryReadValueHandler` on the converter. This handler will allow you to intercept and convert string and

docs/jsonpath/syntax.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ JSONPath operates on JSON documents:
2222
### JSONPath Syntax
2323

2424
| JSONPath | Description
25-
|:---------------------------------------------|:-----------------------------------------------------------
25+
|:---------------------------------------------|:-------------------------------------------
2626
| `$` | Root JSON node
2727
| `@` | Current JSON node
2828
| `.<name>`, `.'<name>'`, or `."<name>"` | Object member dot operator
@@ -38,10 +38,10 @@ JSONPath operates on JSON documents:
3838

3939
The library extends the JSONPath expression syntax to support additional features.
4040

41-
| Operators | Description | Example
42-
|---------------------|-----------------------------------------------|------------------------------------------------
43-
| `+` `-` `*` `\` `%` | Basic math operators. | `$[?(@.a + @.b == 3)]`
44-
| `in` | Tests is a value is in a set. | `$[[email protected] in ['a', 'b', 'c'] ]`
41+
| Operators | Description | Example
42+
|---------------------|---------------------------------|----------------------------------
43+
| `+` `-` `*` `\` `%` | Basic math operators. | `$[?(@.a + @.b == 3)]`
44+
| `in` | Tests is a value is in a set. | `$[[email protected] in ['a', 'b', 'c'] ]`
4545

4646

4747
## JSONPath Operators

src/Hyperbee.Json/Hyperbee.Json.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net9.0</TargetFramework>
3+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
44
<ImplicitUsings>enable</ImplicitUsings>
55
<IsPackable>true</IsPackable>
66

@@ -9,7 +9,6 @@
99
<PackageTags>json-path;jsonpath;json-pointer;jsonpointer;json-patch;jsonpatch;query;path;patch;diff;json;rfc9535;rfc6901;rfc6902</PackageTags>
1010
<PackageIcon>icon.png</PackageIcon>
1111
<PackageProjectUrl>https://stillpoint-software.github.io/hyperbee.json/</PackageProjectUrl>
12-
<TargetFrameworks>net9.0</TargetFrameworks>
1312
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1413
<Copyright>Stillpoint Software, Inc.</Copyright>
1514
<Title>Hyperbee Json</Title>

src/Hyperbee.Json/Patch/JsonDiff.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static void ProcessArrayDiff( DiffOperation operation, Stack<DiffOperati
140140

141141
try
142142
{
143-
CalculateLevenshteinMatrix( matrix, source, target );
143+
CalculateLevenshteinMatrix( ref matrix, source, target );
144144

145145
while ( row > 0 || col > 0 )
146146
{
@@ -177,7 +177,7 @@ private static void ProcessArrayDiff( DiffOperation operation, Stack<DiffOperati
177177
else
178178
{
179179
// We already check if these were values when calculating the matrix,
180-
// so we know this are objects or arrays, and we need further processing.
180+
// so we know this is an object or array, and we need further processing.
181181
stack.Push( new DiffOperation( source[row - 1], target[col - 1], path ) );
182182
}
183183

@@ -201,7 +201,7 @@ private static void ProcessValueDiff( DiffOperation operation, List<PatchOperati
201201
operations.Add( new PatchOperation { Operation = PatchOperationType.Replace, Path = operation.Path, Value = operation.Target } );
202202
}
203203

204-
private static void CalculateLevenshteinMatrix( Matrix matrix, TNode[] source, TNode[] target )
204+
private static void CalculateLevenshteinMatrix( ref Matrix matrix, TNode[] source, TNode[] target )
205205
{
206206
var accessor = Descriptor.ValueAccessor;
207207

src/Hyperbee.Json/Patch/JsonPatch.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,12 @@ private static JsonNode PatchValue( PatchOperation patch )
419419
if ( patch.Value is null )
420420
throw new JsonPatchException( "The 'value' property was missing." );
421421

422-
return (patch.Value is JsonNode node)
423-
? (node.Parent != null ? node.DeepClone() : node)
424-
: JsonValue.Create( patch.Value );
422+
return patch.Value switch
423+
{
424+
JsonNode node when node.Parent == null => node,
425+
JsonNode node => node.DeepClone(),
426+
_ => JsonValue.Create( patch.Value )
427+
};
425428
}
426429

427430
public IEnumerator<PatchOperation> GetEnumerator()

src/Hyperbee.Json/Path/JsonPath.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ private static IEnumerable<TNode> EnumerateMatches( TNode root, NodeArgs args, N
116116

117117
var (parent, value, key, segmentNext, flags) = args;
118118

119-
// call node processor if it exists and the `key` is not null.
120-
// the key is null when a descent has re-pushed the descent target.
121-
// this should be safe to skip; we will see its values later.
119+
ProcessArgs:
120+
// call node processor if it exists and the `key` is not null.
121+
// the key is null when a descent has re-pushed the descent target.
122+
// this should be safe to skip; we will see its values later.
122123

123-
ProcessArgs:
124124
if ( key != null )
125125
processor?.Invoke( parent, value, key, segmentNext );
126126

test/Hyperbee.Json.Cts/Hyperbee.Json.Cts.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFrameworks>net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

test/Hyperbee.Json.Tests/Hyperbee.Json.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net9.0</TargetFramework>
3+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
44
<IsPackable>false</IsPackable>
55
<RootNamespace>Hyperbee.Json.Tests</RootNamespace>
66
</PropertyGroup>

0 commit comments

Comments
 (0)