Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stefh/jsonconverter

Common interface for Json Converters (Newtonsoft.Json, System.Text.Json, SimpleJson and more)
https://github.com/stefh/jsonconverter

Last synced: 18 days ago
JSON representation

Common interface for Json Converters (Newtonsoft.Json, System.Text.Json, SimpleJson and more)

Awesome Lists containing this project

README

        

# JsonConverter

Common interface + implementation for Json Converters:
- [Newtonsoft.Json](https://www.newtonsoft.com/json)
- [System.Text.Json](https://docs.microsoft.com/en-us/dotnet/api/system.text.json)
- [SimpleJson](https://github.com/facebook-csharp-sdk/simple-json)
- [NetJSON](https://github.com/rpgmaker/NetJSON)
- [Utf8Json](https://github.com/neuecc/Utf8Json)
- [XUtf8Json](https://github.com/geeking/Utf8Json)
- [ServiceStack.Text](https://docs.servicestack.net/json-format)
- [Argon](https://github.com/SimonCropp/Argon)

## NuGets

| Name | Version |
| - | - |
| **JsonConverter.Abstractions** | [![NuGet Badge](https://img.shields.io/nuget/v/JsonConverter.Abstractions)](https://www.nuget.org/packages/JsonConverter.Abstractions)
| **JsonConverter.Newtonsoft.Json** | [![NuGet Badge](https://img.shields.io/nuget/v/JsonConverter.Newtonsoft.Json)](https://www.nuget.org/packages/JsonConverter.Newtonsoft.Json)
| **JsonConverter.System.Text.Json** | [![NuGet Badge](https://img.shields.io/nuget/v/JsonConverter.System.Text.Json)](https://www.nuget.org/packages/JsonConverter.System.Text.Json)
| **JsonConverter.SimpleJson** | [![NuGet Badge](https://img.shields.io/nuget/v/JsonConverter.SimpleJson)](https://www.nuget.org/packages/JsonConverter.SimpleJson)
| **JsonConverter.NetJSON** | [![NuGet Badge](https://img.shields.io/nuget/v/JsonConverter.NetJSON)](https://www.nuget.org/packages/JsonConverter.NetJSON)
| **JsonConverter.Utf8Json** | [![NuGet Badge](https://img.shields.io/nuget/v/JsonConverter.Utf8Json)](https://www.nuget.org/packages/JsonConverter.Utf8Json)
| **JsonConverter.XUtf8Json** | [![NuGet Badge](https://img.shields.io/nuget/v/JsonConverter.XUtf8Json)](https://www.nuget.org/packages/JsonConverter.XUtf8Json)
| **JsonConverter.ServiceStack.Text** | [![NuGet Badge](https://img.shields.io/nuget/v/JsonConverter.ServiceStack.Text)](https://www.nuget.org/packages/JsonConverter.ServiceStack.Text)
| **JsonConverter.Argon** | [![NuGet Badge](https://img.shields.io/nuget/v/JsonConverter.Argon)](https://www.nuget.org/packages/JsonConverter.Argon)

## Interfaces

### IJsonConverter

``` csharp
public interface IJsonConverter
{
Task DeserializeAsync(Stream stream, IJsonConverterOptions? options = null, CancellationToken cancellationToken = default);

T? Deserialize(Stream stream, IJsonConverterOptions? options = null);

T? Deserialize(string text, IJsonConverterOptions? options = null);

object? Deserialize(string text, Type type, JsonConverterOptions? options = null);

Task SerializeAsync(object source, IJsonConverterOptions? options = null, CancellationToken cancellationToken = default);

string Serialize(object source, IJsonConverterOptions? options = null);

Task SerializeAsync(Stream stream, object value, JsonConverterOptions? options = null, CancellationToken cancellationToken = default);

Task IsValidJsonAsync(Stream stream, CancellationToken cancellationToken = default);

Task IsValidJsonAsync(string input, CancellationToken cancellationToken = default);

bool IsValidJson(Stream stream);

bool IsValidJson(string input);

///
/// Convert an object to a DynamicJsonClass or DynamicJsonClass-array.
/// .
/// The object (e.g. JObject in case of Newtonsoft.Json).
/// The (optional).
/// object, DynamicJsonClass or DynamicJsonClass-array
object? ConvertToDynamicJsonClass(object value, DynamicJsonClassOptions? options = null);

///
/// Convert Json Text to a DynamicJsonClass or DynamicJsonClass-array.
/// .
/// The Json Text.
/// The (optional).
/// object, DynamicJsonClass or DynamicJsonClass-array
object? DeserializeToDynamicJsonClass(string text, DynamicJsonClassOptions? options = null);
```

### JsonConverterOptions

``` csharp
public class JsonConverterOptions
{
public bool PropertyNameCaseInsensitive { get; set; }

public bool WriteIndented { get; set; }

public bool IgnoreNullValues { get; set; }
}
```

### JsonConverterOptions

``` csharp
public class DynamicJsonClassOptions
{
public JsonConverterOptions? JsonConverterOptions { get; set; }

public IntegerBehavior IntegerConvertBehavior { get; set; } = IntegerBehavior.UseLong;

public FloatBehavior FloatConvertBehavior { get; set; } = FloatBehavior.UseDouble;
}
```