https://github.com/verticalsoftware/vertical-jsonwriter-core
Provides an abstraction over `System.Text.Json.Utf8JsonReader` that handles the structural state of JSON document parsing.
https://github.com/verticalsoftware/vertical-jsonwriter-core
Last synced: 11 months ago
JSON representation
Provides an abstraction over `System.Text.Json.Utf8JsonReader` that handles the structural state of JSON document parsing.
- Host: GitHub
- URL: https://github.com/verticalsoftware/vertical-jsonwriter-core
- Owner: verticalsoftware
- License: mit
- Created: 2023-04-22T21:06:41.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-22T21:31:21.000Z (about 3 years ago)
- Last Synced: 2025-08-01T01:39:24.672Z (11 months ago)
- Language: C#
- Size: 1.11 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vertical-jsonwriter-core
Provides an abstraction over `System.Text.Json.Utf8JsonReader` that handles the structural state of JSON document parsing.
## Overview
Simply put, the `JsonStructureReader` class accepts a `Utf8JsonReader` structure, and forwards node information to a visitor implementation. The node information contains the current depth, parent type, applicable values, property names, etc.
## Quick Start
Add a package reference to your `.csproj` file:
```
$ dotnet add package vertical-jsonwriter-core
```
## Usage
Define an implementation of `IJsonStructureVisitor`:
```csharp
public class MyJsonStructureVisitor : IJsonStructureVisitor
{
// Implement methods...
void VisitObjectStart(in JsonVisitingState state) { /* Implementation */ }
void VisitObjectEnd(in JsonVisitingState state, int childCount) { /* Implementation */ }
void VisitArrayStart(in JsonVisitingState state) { /* Implementation */ }
void VisitArrayEnd(in JsonVisitingState state, int childCount) { /* Implementation */ }
void VisitPropertyName(in JsonVisitingState state, string name) { /* Implementation */ }
void VisitStringValue(in JsonVisitingState state, string value) { /* Implementation */ }
void VisitInt32Value(in JsonVisitingState state, int value) { /* Implementation */ }
void VisitInt64Value(in JsonVisitingState state, long value) { /* Implementation */ }
void VisitDoubleValue(in JsonVisitingState state, double value) { /* Implementation */ }
void VisitDecimalValue(in JsonVisitingState state, decimal value) { /* Implementation */ }
void VisitBooleanValue(in JsonVisitingState state, bool value) { /* Implementation */ }
void VisitNull(in JsonVisitingState state) { /* Implementation */ }
}
```
The `JsonVisitingState` structure contains information regarding the location of the reader that may be of interest:
|Property|Description|
|---|---|
|`Depth`|The current depth level of the reader. Any time the reader descends into an object or array, the depth is incremented.|
|`Index`|The ordinal index of the node within its parent object or array. This property is zero-based.|
|`JsonPlacement`|One of `JsonPlacement` values that describe the location of the current node.|
The `JsonPlacement` enum describes the placement of the current node, relative to its parent:
|Value|Description|
|---|---|
|`RootDocument`|The node is a child of the top-most array or object.|
|`Object`|The node is a child of a JSON object.|
|`Array`|The node is a child of a JSON array.|
|`Property`|The node is the literal value of a property in a JSON object, or a value in a JSON array.|