Very simple:
import json
data = json.loads('{"one" : "1", "two" : "2", "three" : "3"}')
print(data['two']) # or `print data['two']` in Python 2
Answer from John Giotta on Stack OverflowHandling JSON files with ease in Python
Simple tutorials for using reddit api in Python?
Using an API just comes down to making a request to the right end-point (e.g. /api/v1/me), which then returns data. Most of the time this data is in either JSON or XML format.
Now in order to view that end-point (/api/v1/me) you need to be authenticated via OAuth, which is a whole separate process. (But also including making requests by sending the right data back and forth.)
Now to make it easy, you can just use PRAW. Which has a small tutorial on their website. :)
More on reddit.comVideos
Very simple:
import json
data = json.loads('{"one" : "1", "two" : "2", "three" : "3"}')
print(data['two']) # or `print data['two']` in Python 2
For URL or file, use json.load(). For string with .json content, use json.loads().
#! /usr/bin/python
import json
# from pprint import pprint
json_file = 'my_cube.json'
cube = '1'
with open(json_file) as json_data:
data = json.load(json_data)
# pprint(data)
print "Dimension: ", data['cubes'][cube]['dim']
print "Measures: ", data['cubes'][cube]['meas']
I have finished writing the third article in the Data Engineering with Python series. This is about working with JSON data in Python. I have tried to cover every necessary use case. If you have any other suggestions, let me know.
Working with JSON in Python
Data Engineering with Python series