propenster / superfastjsonparser

Writing a superfast JSON parser from scratch in C# - a tutorial series on my YouTube channel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SuperfastJSONparser

A superfast JSON parser written from scratch in C# for my subscribers on YouTube

  • Lexing for normal people
  • Parsing for normal people
  • Reflection in C# for normal people
  • Deserialization

References

Features

  • Fast JSON parsing
  • Low-cost JSON deserialization to plain old CLR objects

Examples

var jsonString = "{\"name\": \"Jason Bourne\", \"isActive\":true, \"nestedObject\": {\"id\":1, \"itemNumber\":\"123AB\"}, \"items\": [1,2,3,4,5], \"nestedObjects\":[{\"id\":1, \"itemNumber\":\"123AB\"}, {\"id\":2, \"itemNumber\":\"149AB\"}], \"age\":43}";

var jsonObject = new OurJSONObject(jsonString);

var sampleObject = jsonObject.GetJSONObject<SampleJSONObject>(string.Empty);

Our sample object type

 public class SampleJSONObject
    {
        public string name {  get; set; } = string.Empty; 
        public bool isActive { get; set; }
        public NestedObject nestedObject { get; set; } = new();
        public List<int> items { get; set; } = new List<int>();
        public List<NestedObject> nestedObjects { get; set; } = new List<NestedObject>();
        public int age { get; set; }

        public override string ToString()
        {
            return string.Format("Name: {0}, isActive: {1}, nestedObject: {2}, items: [ {3} ] age: {4}", name, isActive, nestedObject,items, age);
        }
    }
    public class NestedObject
    {
        public int id { get; set; }
        public string itemNumber { get; set; } = string.Empty;

        public override string ToString()
        {
            return string.Format("{{ id: {0}, itemNumber: {1} }}", id, itemNumber);
        }
    }

About

Writing a superfast JSON parser from scratch in C# - a tutorial series on my YouTube channel


Languages

Language:C# 100.0%