JsonQuery Library

 

Library reference

Install-Package JsonQuery -Version 1.0.2

 

Data

  "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

    }

  }

}

 

Code

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(jsondataquery);

                Console.WriteLine(dataresul);

            }

        }

    }

}

 

Resul

{

  "store": {

    "book": [

      {

        "Category""fiction",

        "Price"12.98

      },

      {

        "Category""fiction",

        "Price"22.99

      }

    ],

    "bicycle": {

      "color""red",

      "price"19.95

    }

  }

}

 

Operators

 

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

      }

    ]

  }

}

 

Examples:

Query 1

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

    }

  }

}

 

Query 2

string query = @"store { book{ Category, Price @== 12.98 }, bicycle }";

{

  "store": {

    "book": [

      {

        "Category""fiction",

        "Price"12.98

      }

    ],

    "bicycle": {

      "color""red",

      "price"19.95

    }

  }

}

 

Query 3

string query = @"store { book{ Category, Price @@== 12.98 }, bicycle }";

{}

 

Query 4

string query = @"store { bookCategory }, bicycle{color @@== red} }";

{

  "store": {

    "book": [

      {

        "Category""reference"

      },

      {

        "Category""fiction"

      },

      {

        "Category""fiction"

      },

      {

        "Category""fiction"

      }

    ],

    "bicycle": {

      "color""red"

    }

  }

}

 

Query 5

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

The parameters do not require defining data types and multiple values can be passed with the "|" separator.

Query 6

string query = @"store { book{ author @== Herman Melville | Evelyn Waugh, Price } }";

{

  "store": {

    "book": [

      {

        "author""Evelyn Waugh",

        "Price"12.98

      },

      {

        "author""Herman Melville",

        "Price"8.99

      }

    ]

  }

}