title: Python: How to get JSON object from a UDP received packet
body: <p>I am sending this temperature and humidity reading using UDP packets across the network but. As UDP only accepts 1 argument, i have put them into a JSON object then a string. When i receive the packet i cannot seem to get out the values i want from the received packet </p>
  
  <pre><code>#!/usr/bin/python
  import sys
  import time
  import socket
  import Adafruit_DHT
  import json
  
  UDP_IP = "192.168.42.18"
  PORT = 5001
  
  my_ip = socket.gethostbyname(socket.getfqdn())
  
  print "server has started",
  
  
  while True:
     humidity, temperature = Adafruit_DHT.read_retry(11, 4)#initialising DHT11 temp sensor
  
     print 'Temp: {0:0.1f} C  Humidity: {1:0.1f} %'.format(temperature, humidity)
     print time.asctime()#printing to the terminal values
  
     json_string = {}
     json_string ['details'] = {'ip': my_ip, 'temp':temperature,  'humidity':humidity}
  
     sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)#initalising socket and UDP connection
     Message = str(json_string)
     print 'Message sent:= ', Message
  
     sock.sendto(Message,(UDP_IP, PORT))
     print "SENT to:-", UDP_IP, PORT, "From", my_ip
  
     time.sleep(3)#delay
  </code></pre>
  
  <p>receiving code</p>
  
  <pre><code>import socket
  import time
  import json
  
  port = 5001
  
  sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
  
  sock.bind(("", port))
  
  print "server started"
  
  while True:
     recieved = sock.recvfrom(1024)
     print type(recieved)
     print recieved[0]
     print time.asctime()#bytes object
  
  
     json_obj = json.dumps(recieved)
  
     print type(json_obj)
  
     print json_obj ['details']['temp']
  
  #json_converted = json.loads(json_obj)
  #print type(json_converted)
  
  #json_string = map(str,(json_converted))
  
     print "converted Json:- "
  #print json_string['details']['temp']
     print "Temperature in Celsuius"
  </code></pre>
  
  <p>I keep getting errors of the wrong format. What is the correct method. </p>
  
  <pre><code>server started
  &lt;type 'tuple'&gt;
  {'details': {'ip': '127.0.1.1', 'temp': 20.0, 'humidity': 49.0}}
  Wed Feb 22 16:27:06 2017
  &lt;type 'str'&gt;
  Traceback (most recent call last):
  File "/Users/Faiz/Desktop/Rpi_Sensors_UDP/sensor_listenerUDP.py", line 24, in     &lt;module&gt;
   print json_obj ['details']['temp']
   TypeError: string indices must be integers, not str
  
  Process finished with exit code 1
  </code></pre>