Skip to content

icarus-consulting/Yaapii.JSON

Repository files navigation

Yaapii.JSON

Build status PRs Welcome EO principles respected here

Repo Guidelines

Mainly responsible for this repository is jaanpeeter. Please request a review in every single PR from him.

He will try to review the PRs within 1 week and merge applied PRs within 2 weeks with a new release. Main review day is thursday.

Overview

Parse and validate JSON data using JSONPath.

With this module you can:

Usage

Given this json:

{
	"name": "jay",
	"purpose": "this json is for testing class JSON which implements IJSON",
	"friends": [
		"Silent Bob"
	],
	"addresses": [
		{
			"name": "Drugstore",
			"type": "default"
		},
		{
			"name": "The mall",
			"type": "alternative"
		}
	]
}

Parse

Parse by creating a new object:

    IJSON json = new JSON(jsonString); //multiple ctors for parsing are available

Read

Retrieve a single value:

    string value = new JSON(data).Value("addresses[0].type"));

Retrieve multiple values:

    IList<string> values = json.Values("addresses[*].type"); //result List will be readonly

Retrieve a single node:

    IJSON node = json.Node("addresses[0]");

Retrieve multiple nodes:

    IList<IJSON> nodes = json.Nodes("addresses[*]"); //result List will be readonly

Retrieve the raw token from the IJSON:

    JToken token = json.Token(); //JToken is part of NewtonSoft.Json package

Patch

var patched = new JSONPatched(unpatched,$"$.addresses[0].name","Quick Stop");

Validate

Validate by decorating your object with StrictJSON:

    var json = "{ \"test\": \"a word\" }";
    var schema = "{ \"type\": \"object\", \"properties\": { \"test\": { \"type\": \"string\" } } }";

    new StrictJSON(
        new JSON(json),
        schema
    ).Value("test"); //Validation is done when trying to read

Contribute

Elegant Objects Rules

This project respects the Elegant Objects Rules. These rules are suggested in the two "Elegant Objects" books.

Here is an overview:

About

Parse and validate JSON data using JSONPath

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors