title: Manipulate JSON with python
body: <p>I'm trying to manipulate JSON data to match a specific format for Ansible. I'm new to python and programming in general.  I can't quite seem to figure out how to do that.  Here's my relevent code:</p>
  
  <pre><code>import os
  import sys
  import argparse
  import ConfigParser
  
  try:
      import json
  except ImportError:
      import simplejson as json
  
  import requests
  
  payload = 'query=SELECT+TOP+10+IPAddress,+Vendor+FROM+Orion.Nodes'
  url = "https://10.150.199.44:17778/SolarWinds/InformationService/v3/Json/Query"
  req = requests.get(url, params=payload, verify=False, auth=('dmitry', 'security'))
  
  jsonget = req.json()
  
  
  def get_list(self):
          hostsData = jsonget
          print "Test json before manipulation:\n"
          print(hostsData)
          print "\n\n"
          for item in hostsData['results']:
              print '' + item['Vendor']
              for item in hostsData['results']:
                  print 'hosts:' + item['IPAddress']
  </code></pre>
  
  <p>This is my output:</p>
  
  <pre><code>./swinds.py --list
  Test json before manipulation:
  
  {u'results': [{u'Vendor': u'Cisco', u'IPAddress': u'10.150.190.2'}, {u'Vendor': u'Cisco', u'IPAddress': u'10.150.250.3'}, {u'Vendor': u'Unknown', u'IPAddress': u'10.255.255.42'}, {u'Vendor': u'Juniper Networks/NetScreen', u'IPAddress': u'10.58.1.1'}, {u'Vendor': u'Cisco', u'IPAddress': u'10.33.93.1'}, {u'Vendor': u'Cisco', u'IPAddress': u'10.33.93.2'}, {u'Vendor': u'Unknown', u'IPAddress': u'10.33.93.3'}, {u'Vendor': u'Cisco', u'IPAddress': u'10.33.93.4'}, {u'Vendor': u'Unknown', u'IPAddress': u'10.33.93.6'}, {u'Vendor': u'Cisco', u'IPAddress': u'10.33.93.7'}]}
  
  
  
      Cisco
  hosts:10.150.190.2
  hosts:10.150.250.3
  hosts:10.255.255.42
  hosts:10.58.1.1
  hosts:10.33.93.1
  hosts:10.33.93.2
  hosts:10.33.93.3
  hosts:10.33.93.4
  hosts:10.33.93.6
  hosts:10.33.93.7
  Cisco
  hosts:10.150.190.2
  hosts:10.150.250.3
  hosts:10.255.255.42
  hosts:10.58.1.1
  hosts:10.33.93.1
  hosts:10.33.93.2
  hosts:10.33.93.3
  hosts:10.33.93.4
  hosts:10.33.93.6
  hosts:10.33.93.7
  Unknown
  ...
  </code></pre>
  
  <p>What I'm trying to do is output something like this Ansible can read:</p>
  
  <pre><code>{
      "Cisco"   : {
          "hosts"   : [ "10.150.190.2", "10.150.250.3" ],
              },
      "Unknown"  : 
          "hosts"   : [ "10.255.255.42" ],
  },
  </code></pre>
  
  <p>Thanks for any help.</p>
  
  <p>CB</p>