CypherPotato.LightJson
0.5.5
See the version list below for details.
dotnet add package CypherPotato.LightJson --version 0.5.5
NuGet\Install-Package CypherPotato.LightJson -Version 0.5.5
<PackageReference Include="CypherPotato.LightJson" Version="0.5.5" />
paket add CypherPotato.LightJson --version 0.5.5
#r "nuget: CypherPotato.LightJson, 0.5.5"
// Install CypherPotato.LightJson as a Cake Addin #addin nuget:?package=CypherPotato.LightJson&version=0.5.5 // Install CypherPotato.LightJson as a Cake Tool #tool nuget:?package=CypherPotato.LightJson&version=0.5.5
LightJson
This project was based in the incredible work LightJson, originally made by Marcos Lopez C.
This fork includes some personal tweaks. It's aimed to read/write JSON messages without automatic type mapping. It alsos does not use Source Generators to read or write messages, which makes it possible to build code with bflat and also features manual object mapping.
Almost everything in this class is inherited from the main project mentioned above, however, there are these changes:
- Unlike the original project, a
JsonValue
does not contain anyAsFoobar
properties, but has a method for eachGetFoobar()
, and the main difference is that you cannot get an implicit value of what the JsonValue is. For example, you cannot readJsonValue.GetBoolean()
if the stored value is a string. - All functions that return an object converted from a JsonValue, such as
JsonValue.GetString()
for example, do not return nullable values. You can check for nullable JSON values usingJsonValue.MaybeNull()
. - You can search for objects in an ignore-case manner if you set
JsonOptions.PropertyNameCaseInsensitive
totrue
. - Undefined values will come with
JsonValueType.Undefined
instead ofJsonValueType.Null
. - This projects only targets .NET 6 and above.
Additionally, this library includes these new features:
Create JsonValues from any kind of object:
object anonymousObject = new
{
foo = "bar"
};
string json = new JsonValue(anonymousObject).ToString();
Create custom mappers (a.k.a. converters):
static void Main(string[] args)
{
JsonOptions.Mappers.Add(new DatetimeMapper());
string json = new JsonValue(DateTime.Now).ToString();
Console.WriteLine(json);
}
public class DatetimeMapper : JsonSerializerMapper
{
public override Boolean CanSerialize(Type obj)
{
return obj == typeof(DateTime);
}
public override Object Deserialize(JsonValue value)
{
return DateTime.Parse(value.GetString());
}
public override JsonValue Serialize(Object value)
{
DateTime t = (DateTime)value;
return new JsonValue(t.ToString("s"));
}
}
Fluent syntax for retrieving items:
// $.foobar must be present, non null and carry an string value.
string stringValue = obj["foobar"].GetString();
// $.bazdaz can be null or undefined, but if not, it must be an string.
string? optionalValue = obj["bazdaz"].MaybeNull()?.GetString();
// $.duzkaz must be present, non null, be an json array and every children on it
// must be an string value.
string[] arrayItems = obj["duzkaz"].GetJsonArray().Select(i => i.GetString()).ToArray();
// $.user must be present, non null, and must be mapped to User, which it's mapper
// is defined on JsonOptions.Mappers.
User user = obj["user"].Map<User>();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CypherPotato.LightJson:
Package | Downloads |
---|---|
Sisk.JsonRpc
This package provides an JSON-RPC 2.0 interface for Sisk projects. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.13.0 | 76 | 12/16/2024 |
0.12.0 | 75 | 12/11/2024 |
0.11.0 | 104 | 11/11/2024 |
0.10.7 | 81 | 10/25/2024 |
0.10.6 | 103 | 10/10/2024 |
0.10.5 | 103 | 9/30/2024 |
0.10.4 | 97 | 9/26/2024 |
0.10.3 | 101 | 9/26/2024 |
0.10.1 | 119 | 8/30/2024 |
0.10.0-beta4 | 89 | 8/27/2024 |
0.10.0-beta3 | 105 | 8/26/2024 |
0.10.0-beta1 | 118 | 8/23/2024 |
0.9.3 | 128 | 7/18/2024 |
0.9.2 | 127 | 7/3/2024 |
0.9.1 | 120 | 7/1/2024 |
0.9.0 | 116 | 5/28/2024 |
0.9.0-beta3 | 102 | 5/14/2024 |
0.9.0-beta2 | 114 | 5/4/2024 |
0.9.0-beta1 | 64 | 5/2/2024 |
0.8.0 | 129 | 4/4/2024 |
0.7.0 | 121 | 3/24/2024 |
0.6.0 | 144 | 1/18/2024 |
0.5.6 | 205 | 12/6/2023 |
0.5.5 | 155 | 11/30/2023 |