save progress
This commit is contained in:
@@ -12,6 +12,7 @@ This library provides canonical JSON serialization that produces bit-identical o
|
||||
- **No Whitespace**: Compact output with no formatting variations
|
||||
- **Consistent Hashing**: SHA-256 hashes are always lowercase hex
|
||||
- **Cross-Platform**: Same output across Windows, Linux, containers
|
||||
- **Stable Defaults**: Default serialization uses camelCase naming and UnsafeRelaxed JSON escaping (override with custom options)
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -51,6 +52,12 @@ byte[] canonical = CanonJson.CanonicalizeParsedJson(rawJson);
|
||||
// Result: {"a":2,"z":1}
|
||||
```
|
||||
|
||||
If you need stricter escaping rules for raw JSON, pass a custom encoder:
|
||||
|
||||
```csharp
|
||||
byte[] canonical = CanonJson.CanonicalizeParsedJson(rawJson, JavaScriptEncoder.Default);
|
||||
```
|
||||
|
||||
### Custom Serialization Options
|
||||
|
||||
```csharp
|
||||
@@ -62,6 +69,10 @@ var options = new JsonSerializerOptions
|
||||
byte[] canonical = CanonJson.Canonicalize(obj, options);
|
||||
```
|
||||
|
||||
Notes:
|
||||
- Default naming policy is `JsonNamingPolicy.CamelCase` for the object-to-JSON step.
|
||||
- Default encoder is `JavaScriptEncoder.UnsafeRelaxedJsonEscaping` for canonical output.
|
||||
|
||||
## API Reference
|
||||
|
||||
| Method | Description |
|
||||
@@ -69,6 +80,7 @@ byte[] canonical = CanonJson.Canonicalize(obj, options);
|
||||
| `Canonicalize<T>(obj)` | Serialize and canonicalize an object |
|
||||
| `Canonicalize<T>(obj, options)` | Serialize with custom options and canonicalize |
|
||||
| `CanonicalizeParsedJson(bytes)` | Canonicalize existing JSON bytes |
|
||||
| `CanonicalizeParsedJson(bytes, encoder)` | Canonicalize existing JSON with a custom encoder |
|
||||
| `Sha256Hex(bytes)` | Compute SHA-256, return lowercase hex |
|
||||
| `Sha256Prefixed(bytes)` | Compute SHA-256 with "sha256:" prefix |
|
||||
| `Hash<T>(obj)` | Canonicalize and hash in one step |
|
||||
|
||||
Reference in New Issue
Block a user