Adionditsak
Adionditsak

Reputation: 185

Return JSON object problems

I have these lines:

 r = requests.post(url, data=json.dumps(data), headers=headers)

 json_output = r.json()

 print(json_output["hits"]["hits"])

Where I get to this response:

[
  {
    u'sort': [
      1414496113003
    ], 
    u'_type': u'syslog', 
    u'_index': u'logstash-2014.10.28', 
    u'_score': None, 
    u'fields': {
      u'@timestamp': u'2014-10-28T11:35:13.003Z', 
      u'syslog_hostname': u'hostname'
    }, 
    u'_id': u'kq9DHVRCSkmTrSr9VJnURA'
  }
]

I only need to get the "@timestamp". How do I manage? I guess I have to do more to print(json_output["hits"]["hits"])?

Upvotes: 0

Views: 42

Answers (1)

Mauro Baraldi
Mauro Baraldi

Reputation: 6575

print json_output[0]['fields']['@timestamp']

Upvotes: 2

Related Questions