Giter Site home page Giter Site logo

jsonextensions's Introduction

JsonParser

Fast Forward reader using Utf8JsonReader.

This fast forward reader is useful if you want to iterate all over the JSON data with a minimum memory allocation.

This extensions is using the Utf8JsonReader that is a high-performance JSON parser that reads from a ReadOnlySpan<byte> and is able to read the JSON data without allocating memory for the JSON data.

You can read more about the Utf8JsonReader here.

As the Utf8JsonReader is a ref struct, it's complicated to use it to return an IENumerable<T> (using yield), and even from an async method.

This JsonReader class allows you to iterate over the JSON data using a simple foreach loop.

using var jsonReader = new JsonReader(GetFileStream(), 1024); // test 10 to see buffer increase in debug console

foreach (var prop in jsonReader.Values())
{
    if (prop.TokenType == JsonTokenType.StartObject || prop.TokenType == JsonTokenType.StartArray || prop.TokenType == JsonTokenType.EndObject || prop.TokenType == JsonTokenType.EndArray)
        Console.WriteLine($"- ({prop.TokenType})");
    else if (prop.TokenType == JsonTokenType.PropertyName)
        Console.WriteLine($"Property: {prop.Name}");
    else
        Console.WriteLine($"Value: {prop.Value}");
}
- (StartObject)
Property: tableName
Value: Address
Property: schemaName
Value: dbo
Property: version
Value: 1
Property: columns
- (StartArray)
- (StartObject)
Property: name
Value: AddressID
Property: type
Value: int
- (EndObject)
- (StartObject)
Property: name
Value: Country
Property: type
Value: string
- (EndObject)
- (EndArray)
- (EndObject)

jsonextensions's People

Contributors

mimetis avatar jpmikkers avatar edwardmiller-mesirow avatar

Stargazers

Damien Dussart avatar Edward Miller avatar  avatar Gelez avatar  avatar

Watchers

 avatar  avatar

jsonextensions's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.