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: 8 months ago
JSON representation
Common interface for Json Converters (Newtonsoft.Json, System.Text.Json, SimpleJson and more)
- Host: GitHub
- URL: https://github.com/stefh/jsonconverter
- Owner: StefH
- License: mit
- Created: 2022-08-12T17:02:00.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-06-13T17:15:42.000Z (12 months ago)
- Last Synced: 2025-06-15T18:29:23.385Z (12 months ago)
- Language: C#
- Homepage:
- Size: 127 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
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** | [](https://www.nuget.org/packages/JsonConverter.Abstractions)
| **JsonConverter.Newtonsoft.Json** | [](https://www.nuget.org/packages/JsonConverter.Newtonsoft.Json)
| **JsonConverter.System.Text.Json** | [](https://www.nuget.org/packages/JsonConverter.System.Text.Json)
| **JsonConverter.SimpleJson** | [](https://www.nuget.org/packages/JsonConverter.SimpleJson)
| **JsonConverter.NetJSON** | [](https://www.nuget.org/packages/JsonConverter.NetJSON)
| **JsonConverter.Utf8Json** | [](https://www.nuget.org/packages/JsonConverter.Utf8Json)
| **JsonConverter.XUtf8Json** | [](https://www.nuget.org/packages/JsonConverter.XUtf8Json)
| **JsonConverter.ServiceStack.Text** | [](https://www.nuget.org/packages/JsonConverter.ServiceStack.Text)
| **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;
}
```
## Sponsors
[Entity Framework Extensions](https://entityframework-extensions.net/?utm_source=StefH) and [Dapper Plus](https://dapper-plus.net/?utm_source=StefH) are major sponsors and proud to contribute to the development of **JsonConverter**.
[](https://entityframework-extensions.net/bulk-insert?utm_source=StefH)
[](https://dapper-plus.net/bulk-insert?utm_source=StefH)