JsonRazor 1.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonRazor --version 1.4.0
NuGet\Install-Package JsonRazor -Version 1.4.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JsonRazor" Version="1.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonRazor --version 1.4.0
#r "nuget: JsonRazor, 1.4.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JsonRazor as a Cake Addin
#addin nuget:?package=JsonRazor&version=1.4.0

// Install JsonRazor as a Cake Tool
#tool nuget:?package=JsonRazor&version=1.4.0

1.4.0:

Changes to existing code:

  • JsonToken.From() returns JsonComposite instead of JsonToken.
  • Serializer.WriteTokensReadable()'s members and flag arguments has been removed,
  • Deserializer.LeftoverCount and alike structures have been removed,
  • JsonObject.Append(...) methods and JsonArray.Append(...) methods have been deprived of safeCopy and type arguments,
  • Extensions, namely ToJsonArray(), ToJsonObject(), AddRange() have been deprived of safeCopy and type arguments,
  • When deserializing model with constructor, public and private constructors could be used regardless of BindingFlags specified,
  • Deserializer no longer uses automatic code generation to speed up big array deserialization. This functionality has been moved to separate type.
  • ... anything I might have forgotten about.

Fixes:

  • Support for null in JsonArray is extended for objects & arrays. Token's Remove(), SwapFor(), array's Append(), ToJsonArray() methods no longer leave array in state with corrupted indexing.
  • Serializer.WriteReadable or Produce (can't quite remember) would throw when serializing (for instance floats) on non-english culture environment. All serialization should now use invariant culture.
  • Removed faulty recursion in AddRange() extension methods that used params.
  • Fixed rare bug when null would serialize with quotes.
  • Fixed DateTime serialization to consistently use "s" (sortable - yyyy-MM-ddThh:mm:ss) formatting. Serialization format might be target feature for next release.

New features:

  • JsonValue.ToUtcDateTime() conversion method (just DateTime.Parse really). ToBool(), ToLong(), ToDouble() and ToUtcDateTime() have been introduced for JsonToken as well.
  • JsonToken.Index read-only property was introduced. It contains index of token inside array. Could be used for sorting, when grouping of elements by type is disastrous, and original order is needed.
  • JsonArray.TokensWithNulls() extension method, that enumerates tokens, taking into consideration null positions (normal enumeration omits null tokens).
  • JsonObject.ToJsonObject() extension method, that creates object from dictionary output (IEnumerable<KeyValuePair<string,string>>). Key is assumed to be token's name, and Value is JsonToken value.
  • Deserializer.UseNameOrOmit property that allows to configure Serializer and Deserializer to look for [JsonName] and [JsonOmit] attributes. It may marginally improve performance if these attributes aren't used.
  • Time has finally came to make razor suitable for asp.net server environment (pun intended). Certain methods have been inspected in terms of thread safety, and those that could be changed, were rewritten in order to enable concurrency. Methods that are tested to be thread safe:
    • JsonToken.From(string),
    • Deserializer.Consume(string),
    • Deserializer.Consume(JsonToken),
    • Serializer.ProduceTokens(T)

The rule of thumb to guess thread safety is: if it uses StreamReader/Writer or char[] buffer, it may not be thread safe.

  • New serialization types have been introduced in order to make serialization concurrent. New types:
    • CachingSerializer,
    • CachingDeserializer,
    • CodeGenDeserializer.

Each given class takes number of configuration parameters or is constructed via global Serializer or Deserializer configuration, and maintains its settings, regardless is global settings change. After initial configuration, their own settings should not change. Additionally, each instance may be reused to perform multiple serializations or deserializations, which should yield speed improvements for consecutive operations on same model type. CachingSerializer class allows to specify own buffer instance, hence it supports wider range of thread-safe methods than static Serializer. CodeGenDeserializer performs dynamic code compilation, hence it should be cached for frequently used model types.

  • Added IToken.Convert(T) and JsonStream.StreamConverted() methods that support Deserialization.
  • All serialization and deserialization methods previously available use new types under the hood. Some of method docs have been updated to reflect that.

Performance:

  • Reduced size of allocation for IEnumerator<JsonObject> or IEnumerator<JsonArray>.
  • New serialization classes can reduce number of allocations during whole process, depending on the input.
  • Increased performance when using CachingDeserializer on array with nested types.
  • Generated code is shorter and more efficient with value types.
  • Tests reported gigantic speed improvement when using new code (CachingSerializer). Test input array with 50 and 100 objects was serializing 65 - 75% faster. The tradeoff is that single object serialization may perform comparably or marginally worse.

This is one of biggest updates ever made to JsonRazor, in terms of edited code size. Altho set of tests has been extended, it is still possible for bugs to occur. I encourage You to post issues in public repo when any of these happen. Fuggit, even email me in emergent cases. Have a nice day.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net is compatible.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.2 1,274 2/6/2022
2.0.1-rc 832 12/11/2021
2.0.0-rc 992 7/4/2021
1.5.1 2,205 9/27/2019
1.5.0 1,350 7/27/2019
1.4.0 1,385 6/5/2019
1.3.1 1,559 1/25/2019
1.3.0 1,501 1/1/2019
1.2.2.8 1,886 7/6/2018
1.2.2.7 1,844 6/25/2018
1.2.2.6 1,703 6/9/2018
1.2.2.5 2,005 3/31/2018
1.2.2.2 1,892 10/7/2017
1.2.2.1 1,787 10/4/2017
1.2.2 1,825 10/1/2017
1.2.0.1 1,768 8/15/2017
1.1.0.10 1,902 6/25/2017

Multithreading support, bug fixes and performance improvements. Check changelog for details.