JsonQuery Library
Install-Package JsonQuery -Version 1.0.2
{
"store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.98
},
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{ "category": "fiction",
"author": "Nigel Rees",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
using System;
using System.IO;
using JsonQueryLib;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
using (StreamReader reader = File.OpenText(@"file.json"))
{
var jsondata = reader.ReadToEnd();
JsonQuery jsonQuery = new JsonQuery();
string query = @"store {
book{
Category,
Price @>= 12.98
},
bicycle
}";
var dataresul = jsonQuery.GetJson(jsondata, query);
Console.WriteLine(dataresul);
}
}
}
}
{
"store": {
"book": [
{
"Category": "fiction",
"Price": 12.98
},
{
"Category": "fiction",
"Price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
|
|
Local |
Object |
Global Object |
|
Equal to |
== |
@== |
@@== |
|
Greater than |
> |
@> |
@@> |
|
Less than |
< |
@< |
@@< |
|
Greater than equal to |
>= |
@>= |
@@>= |
|
Less than equal to |
<= |
@<= |
@@<= |
Operators Level{
"store": {
"book": [
![]()
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.98
}
]
}
}
string query = @"store { book{ Category, Price == 12.98 }, bicycle }";
{
"store": {
"book": [
{
"Category": "reference"
},
{
"Category": "fiction",
"Price": 12.98
},
{
"Category": "fiction"
},
{
"Category": "fiction"
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
string query = @"store { book{ Category, Price @== 12.98 }, bicycle }";
{
"store": {
"book": [
{
"Category": "fiction",
"Price": 12.98
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
string query = @"store { book{ Category, Price @@== 12.98 }, bicycle }";
{}
string query = @"store { book{ Category }, bicycle{color @@== red} }";
{
"store": {
"book": [
{
"Category": "reference"
},
{
"Category": "fiction"
},
{
"Category": "fiction"
},
{
"Category": "fiction"
}
],
"bicycle": {
"color": "red"
}
}
}
Modification of names
string query = @"store { book{ CATEGORY, author, title } }";
{
"store": {
"book": [
{
"CATEGORY": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century"
},
{
"CATEGORY": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour"
},
{
"CATEGORY": "fiction",
"author": "Herman Melville",
"title": "Moby Dick"
},
{
"CATEGORY": "fiction",
"author": "Nigel Rees",
"title": "The Lord of the Rings"
}
]
}
}
Parameters
string query = @"store { book{ author @== Herman Melville | Evelyn Waugh, Price } }";
{
"store": {
"book": [
{
"author": "Evelyn Waugh",
"Price": 12.98
},
{
"author": "Herman Melville",
"Price": 8.99
}
]
}
}