Created
July 26, 2017 16:06
-
-
Save kdeenanauth/958b321b290c7435eec138223e94c9d1 to your computer and use it in GitHub Desktop.
Python JSON Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Loaded JSON\n" | |
] | |
} | |
], | |
"source": [ | |
"import json\n", | |
"json_str = \"\"\"\n", | |
"{\n", | |
" \"a\": \"val1\", \n", | |
" \"b\": {\n", | |
" \"nested_c\": \"nested_val2\", \n", | |
" \"nested_d\": \"nested_val3\"\n", | |
" }\n", | |
"}\"\"\"\n", | |
"\n", | |
"json_val = json.loads(json_str)\n", | |
"print(\"Loaded JSON\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"val1\n" | |
] | |
} | |
], | |
"source": [ | |
"print(json_val['a'])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"nested_val2\n" | |
] | |
} | |
], | |
"source": [ | |
"print(json_val['b']['nested_c'])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"nested_val3\n" | |
] | |
} | |
], | |
"source": [ | |
"print(json_val['b']['nested_d'])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment