-1

I'm new to json. I have to filter json data using linq to json query in C#.I have to retrieve multiple values from the below sample json data:

{
    "parts": [
    {

      "attributes": {
        "Motherboard": "Gigabyte GA-H81M-S2H",
        "Max RAM": "16GB",
        "Form Factor": "Micro ATX",
        "RAM Slots": 2,
        "Socket / CPU": "LGA1150"
      },
      "type": "Motherboard",
      "name": "Gigabyte GA-H81M-S2H",
      "slug": "gigabyte-motherboard-gah81ms2h"
    },
    {
        "attributes": {
        "Motherboard": "MSI H55-G43",
        "Max RAM": "16GB",
        "Form Factor": "ATX",
        "RAM Slots": 4,
        "Socket / CPU": "LGA1156"
      },
      "type": "Motherboard",
      "name": "MSI H55-G43",
      "slug": "msi-motherboard-h55g43"
    },
    {
      "url": "http://pcpartpicker.com/part/asus-motherboard-rampageivblackedition",
      "attributes": {
        "Motherboard": "Asus Rampage IV Black Edition",
        "Max RAM": "128GB",
        "Form Factor": "EATX",
        "RAM Slots": 8,
        "Socket / CPU": "LGA2011"
      },
      "type": "Motherboard",
      "name": "Asus Rampage IV Black Edition",
      "slug": "asus-motherboard-rampageivblackedition"
    }
 ],

}

please help me with query how to select multiple (key,values) using where clause.I have to select name,slug,form factor,motherboard using where clause.

Liam
  • 27,717
  • 28
  • 128
  • 190
Rajesh
  • 55
  • 2
  • 11
  • 2
    possible duplicate of [Can I LINQ a JSON?](http://stackoverflow.com/questions/18758361/can-i-linq-a-json) – Liam Aug 26 '15 at 11:03

1 Answers1

0

You need to first create classes with respect to your JSON content structure. This free online tool can help you creating C# classes from JSON data easily. Then you will need to parse this JSON to an object of C# class.

After that, you can perform LINQ operations on this object, filter them and parse back to the JSON if required.

You can use Json.NET for all serialization and de-serialization operations.

Study this great article for writing LINQ queries.

shashwat
  • 7,851
  • 9
  • 57
  • 90
  • thanks for your suggestions,but what i want to know is how to write linq query to retrieve those values. – Rajesh Aug 26 '15 at 11:33
  • First create classes as I've suggested and then try writing `LINQ` by yourself. I will help then with specific queries (if any). – shashwat Aug 26 '15 at 12:32