JsonRazor 1.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonRazor --version 1.5.0
NuGet\Install-Package JsonRazor -Version 1.5.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.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonRazor --version 1.5.0
#r "nuget: JsonRazor, 1.5.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.5.0

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

1.5.0:

Changes to existing code:

  • Updated method docs for conversion methods in AbstractString and JsonValue, JsonArray & JsonObject copy constructors, and some other methods.
  • ToJsonObject(IEnumerable<JsonToken>) extension method now does not accepts nulls.
  • ToJsonObject(IEnumerable<KeyValuePair<string,string>>) extension method now does not allow null keys.
  • ToJsonArray(IEnumerable<JsonObject> or IEnumerable<JsonArray>) extension methods now accept null items.
  • Serialization.TokensFromTypeReadable() method has been renamed to TokensReadable(). My bad, it havent even taken type argument.
  • AbstractString's ToInt32(), ToInt64() and ToSingle() methods have been renamed to their respective type keyword (ToInt(), ToLong() and ToFloat()), what matches with style that JsonToken/JsonValue use.
  • One of bool flags in JsonStream.StreamFile() (caching, IIRC), was removed. It made no further sense. Also current StreamFile's caching strategy is to always cache tokens, regardless of Include() being called or not. For scenarios involving using IToken out of enumeration use DrawTokens() instead.
  • IToken.Include() will now throw InvalidOperationException when called after enumerator has been disposed. Usually rewording of linq methods helps resolve this issue.
  • Both JsonStream's StreamFile() and StreamConverted() will throw InvalidOperationException when being enumerated again with captured enumerable instance.
  • Usage of IToken.QueryTokens() for json object is discouraged. Use indexer instead (it's also a lot more sensible).
  • IToken.Include() got bool argument with default value = true, which doesn't alter current behaviour in any way.

Fixes:

  • GetHashCode() would throw exceptions in certain cases.
  • AbstractString[int] wouldn't throw IndexOutOfRangeException in some cases.
  • AbstractString.ToInt64() and ToInt32() wouldn't parse consistently with JsonValue.IntStyle.
  • When parsed with Json.ValueCorrectnessChecks flag set, incorrect and quoted value would pass validation in some cases. Also string detection via detectString args would incorrectly behave in such cases.
  • JsonToken and JsonValue SetValue() methods would sometimes misbehave in terms of quotes and null replacement. Currently null string is converted to runtime null only if it was written without quotes, whereas quoted or "" should remain unchanged.
  • JsonToken or JsonValue, produced by IToken.Convert(), Value or ToString() would in rare cases violate said rules.
  • Both JsonStream.StreamFile() and StreamConverted() wouldn't clear cache when enumeration wasn't full.
  • Parsing from StreamReader in some cases would cause stream retention that prevented garbage collection. That issue has been resolved for fully parsed source. In other case Dispose() static method should be called. This issue should be addressed in future releases.
  • JsonStream.StreamFile() would behave unpredictable in some cases.
  • IToken.Include() wouln't cause parsing to happen in some cases.

New features:

  • IJsonNameStyle interface, that you may implement to easily convert member names to any custom format. Pass an instance to Deserialization' or Serialization' NameStyle property. [JsonName] has a precedence over style, so backward compatibility with older model definitions is maintained. Member names are computed only once for given type. Also constructor parameter names remain untouched.
  • Serialization basic support for writing JsonComposite that is in object type field or property as part of regular model. This is complementary functionality to deserialization of undefined type.
  • JsonToken.ToTokenDictionary() extension method, that takes all object's tokens and puts in dictionary.
  • JsonToken.Add(JsonToken) method, that allows calling Append() from JsonToken type.
  • JsonToken.ValueCount virtual property to ease access to array one.
  • JsonToken.From(StreamReader) that returns unparsed token, just like string equivalent does.
  • JsonToken.Read(string) that returns parsed token, just like stream equivalent does.
  • ICommonToken interface, that both JsonToken and IToken implement (some of members, like indexer, explicitly), so that base operations could be performed interchangeably. Take into account that IToken needs to be casted.
  • IToken.Included() method, that does exactly what Include() does, but returns passed value of included (true by default). It can be used conveniently inside lambda expressions with predicates, so calls like Where(t ⇒ predicate).Select(t ⇒ t.Include()) could be shorten to Where(t ⇒ predicate ? t.Included() : false), or even Where(t ⇒ predicate && t.Included()).
  • JsonStream.DrawTokens() method that is designed purely to return tokens ready for operations outside of enumerable processing. In order to parse token it is advised to use Include() or Included() method. Alternatively, Count and ValueCount properties will cause immediate parsing, but may mess up caching strategy (ie. when Count is used for testing) - in such cases passing false to Include() or Included() after calling Count will cause token to be normally cached.
  • New compilation target: .NET Core 2.1, and AbstractString.ToSpan() method.

Performance:

  • Reduced number of allocations for IToken deserialization under .NET Core 2.1
  • Reduced size of internal allocations made by CachingSerializer.
  • Reduced size of assembly around 2kb. Enumerator allocations done by JsonComposite.AsLazy() and JsonArray.Values() were reduced.
  • Array deserialization allocates less garbage.
  • JsonToken.Write() causes less allocations. Also its parformance for deeply nested structures improved marginally.
  • Object hashing got more attention (I was bout to delete this, coz it was purely useless). But before i did that, whole hashing was rewritten using different algorithm. Both hashing process and lookup time decreased around 20-30%, memory usage decreased ~15%. Also JsonObject instance size went down. So, according to my tests, with around 50 tokens inside object, both execution time of full lookup using linear search, and full lookup using hashing + hashing time were approximately equal, (in some cases even 40 was faster for hashing), and starting from ~60 keys hashing is consistently faster. So it seems that hashing has its worth. Altho it may speed up ie. deserialization in some cases, it isn't performed by default.
  • Deserialization using CachingDeserializer with object IToken should be noticeably faster, probably around 10-20%.
  • Regular parsing from StreamReader should be marginally faster. Also reduced number of allocations.

Next versions may target reading and writing of comments alongside json token hierarchy, default value serialization behaviour (0, false), enum serialization format (text / number) and further performance improvements. There are also things i'd try out but don't have specified desings in mind.

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 is compatible.  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.
  • .NETCoreApp 2.0

    • No dependencies.
  • .NETCoreApp 2.1

    • No dependencies.
  • .NETFramework 3.5

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

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

New features, bug fixes and performance improvements. Check changelog on nuget.org for details.