0

I am trying to extract one value from JSON.

search_results = urllib2.urlopen(request)
for result in search_results:
    print result;

printing result

{"preview":false,"offset":1,"lastrow":true,"result":{"_bkt":"main~48~BF0767A8-59E9-4783-BB86-F5693835BF2F","_cd":"48:395947656","_indextime":"1369783573","_raw":"2013-05-28 23:05:43 3094 100.244.106.180 200 TCP_NC_MISS 321 967 GET http www.naver.com 80 /include/themecast/menu_count.json - - - - www.naver.com text/html;%20charset=UTF-8 \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/277.0.1453.93 Safari/537.36\" OBSERVED \"Central_AllWhiteList\" - 104.244.128.30 SG-HTTP-Service 55707 - \"Central_AllWhiteList;Central_AllDoNotAuth;Search Engines/Portals\" http://www.naver.com/ json http://www.naver.com/include/themecast/menu_count.json 63.80.4.67 www.naver.com","_serial":"1","_si":["test.com","main"],"_sourcetype":"Bluecoat","_time":"2013-05-28 16:05:43.000 PDT","host":"dssd-sdfsd-001","index":"main","linecount":"1","source":"D:\\OutSPLNK\\SG__10_244_128_30__052813__230919.log.gz","sourcetype":"sadqw","splunk_server":"test.com"}}

I would like to extract value from the key ['_raw'] What is the way to do that?

1
  • JSON is text and urlopen returns a string. The JSON must be parsed to an object model (with a library) before components can be trivially accessed. Knowing the process, many useful results can be found by "parse JSON". Commented May 29, 2013 at 0:11

1 Answer 1

5

Something like:

import json
json_data = json.loads(result)
stuff = json_data['result']['_raw']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.