Skip to content

masaftic/JSONSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

Basic JSON Parsing in C# from Scratch

A lightweight C# project for basic JSON parsing, providing functionality to lex JSON files, parse them into C# objects, and stringify C# objects.

Features

  • Lexer:

    • Lex JSON files to tokenize them for parsing.
  • Parser:

    • Parse JSON files into C# objects.
    • Support for basic data types such as numbers, bools, strings, arrays, and objects.
  • Stringify:

    • Convert C# objects back to JSON strings.

Classes Usage

  1. Lexer:

    var lexer = new Lexer(@" {"id": 4} "); // init lexer with source
    Console.WriteLine(lexer.GetTokens());  // get tokens
  2. Parser:

    var parser = new Parser(lexer.GetTokens()); // init parser with tokens
    JSON json = parser.Parse();                 
  3. Stringify:

    var printer = new PrettyPrinter();
    Console.WriteLine(printer.Stringifiy(json));
  4. Nested Access:

    Console.WriteLine(json["properties:age:title"]);
    Console.WriteLine(json["required:1"]);

Getting Started

Prerequisites

Installation

  • Clone the repository:
> git clone https://github.com/masaftic/JSONSharp
  • Run the project:
> cd JSONSharp/
> dotnet run <File>

About

basic JSON parsing in c# from scratch

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages