title: Python Grouping JSON objects using single object
body: <p>I am using python to format a JSON file, and push it database. I want to group the values based on <strong>Name</strong> to get orders information for each customer. I wasn't able to get the right logic to get the common value(Names) out and group it based on the common value. Can anyone please help me.
  I am new to python and I have written the following logic. The output to this logic is shown below.</p>
  
  <pre><code>for row1 in cb1.n1ql_query(nql):
     col_counts += 1
     result["Category"] = row1['category']
     result["Items"] = row1['item']
     result1["Name"] = row1['name']
     result1 = result
     print(result1)
  </code></pre>
  
  <p>Output JSON:</p>
  
  <pre><code>[
    {
      "Items": [
        "Item1",
        "Item2",
        "Item3"
      ],
      "Category": "Food",
      "Name": "Rick"
    },
    {
      "Items": [
        "Item1",
        "Item2"
      ],
      "Category": "Drink",
      "Name": "Michael"
    },
    {
      "Items": [
        "Item1"
      ],
      "Category": "Drink",
      "Name": "Rick"
    },
    {
      "Items": [
        "Item1",
        "Item2"
      ],
      "Category": "Food",
      "Name": "Michael"
    },
    {
      "Items": [
        "Item1",
        "Item2",
        "Item3",
        "Items4"
      ],
      "Category": "Accessories",
      "Name": "Rick"
    }
  ]
  </code></pre>
  
  <p>I want the JSON in the following format</p>
  
  <pre><code>{
  "Rick":[
      {
  
          "Category": "Food",
          "Items": [
                      "Item1",
                      "Item2",
                      "Item3"
                  ]
      },
      {
          "Category": "Drink",
          "Items": [
                      "Item1"
                  ]
      },
      {
          "Category": "Accessories",
          "Items": [
                      "Item1",
                      "Item2",
                      "Item3",
                      "Items4"
                  ]
      }
  ],
  "Michael":[
      {
          "Category": "Drink",
          "Items": [
                      "Item1",
                      "Item2"
                  ]
      },
      {
          "Category": "Food",
          "Items": [
                      "Item1",
                      "Item2"
                  ]
      }
  
  ]}
  </code></pre>