TinyJson 1.0.0

dotnet add package TinyJson --version 1.0.0                
NuGet\Install-Package TinyJson -Version 1.0.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="TinyJson" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TinyJson --version 1.0.0                
#r "nuget: TinyJson, 1.0.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 TinyJson as a Cake Addin
#addin nuget:?package=TinyJson&version=1.0.0

// Install TinyJson as a Cake Tool
#tool nuget:?package=TinyJson&version=1.0.0                

A really simple C# JSON parser in ~300 lines

  • Attempts to parse JSON files with minimal GC allocation
  • Nice and simple "[1,2,3]".FromJson<List<int>>() API
  • Classes and structs can be parsed too!
class Foo 
{ 
  public int Value;
}
"{\"Value\":10}".FromJson<Foo>()
  • Anonymous JSON is parsed into Dictionary<string,object> and List<object>
var test = "{\"Value\":10}".FromJson<object>();
int number = ((Dictionary<string,object>)test)["Value"];
  • No JIT Emit support to support AOT compilation on iOS
  • Attempts are made to NOT throw an exception if the JSON is corrupted or invalid: returns null instead.
  • Only public fields and property setters on classes/structs will be written to

Limitations:

  • No JIT Emit support to parse structures quickly
  • Limited to parsing <2GB JSON files (due to int.MaxValue)
  • Parsing of abstract classes or interfaces is NOT supported and will throw an exception.

Example Usage

This example will write a list of ints to a File and read it back again:

using System;
using System.IO;
using System.Collections.Generic;

using TinyJson;

public static class JsonTest
{
  public static void Main(string[] args)
  {
    //Write a file
    List<int> values = new List<int> { 1, 2, 3, 4, 5, 6 };
    string json = values.ToJson();
    File.WriteAllText("test.json", json);
    
    //Read it back
    string fileJson = File.ReadAllText("test.json");
    List<int> fileValues = fileJson.FromJson<List<int>>();
  }
}

Save this as JsonTest.cs then compile and run with mcs JsonTest.cs && mono JsonTest.exe

Installation

Simply copy and paste the JSON Parser and/or the JSON Writer into your project. I also provide NuGet but I recommend the copy paste route 😉

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TinyJson:

Package Downloads
Translate_KZ

So if you using MT message for banking operation or Posting messages for companies. You can send transliteration message on QAZAQ your partners.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 13,552 12/3/2017
0.9.1 2,041 11/21/2015