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.
Parse and validate JSON data using JSONPath.
With this module you can:
- Parse JSON data
- Patch JSON data
- Slice portions of JSON data using
- Validate JSON data against a [https://json-schema.org](JSON Schema)
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 by creating a new object:
IJSON json = new JSON(jsonString); //multiple ctors for parsing are availableRetrieve 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 readonlyRetrieve a single node:
IJSON node = json.Node("addresses[0]");Retrieve multiple nodes:
IList<IJSON> nodes = json.Nodes("addresses[*]"); //result List will be readonlyRetrieve the raw token from the IJSON:
JToken token = json.Token(); //JToken is part of NewtonSoft.Json packagevar patched = new JSONPatched(unpatched,$"$.addresses[0].name","Quick Stop");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 readThis project respects the Elegant Objects Rules. These rules are suggested in the two "Elegant Objects" books.
Here is an overview:
- no null
- no getters or setters
- no code execution in ctors
- no mutable objects
- no static methods
- no type casting
- implementation inheritance
- no data transfer objects
- Four member variables maximum
- Five public methods maximum
- Strict method naming
- Every type is an interface
- No code execution in constructors
- No class inheritance, except for design pattern "Envelopes"
- and more