-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2250 from jupyter-naas/2249-json-get-keys
JSON: Add Get keys
- Loading branch information
Showing
1 changed file
with
267 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "80380015-ba38-424d-bcdd-9f68d1e9cdb4", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"<img width=\"10%\" alt=\"Naas\" src=\"https://landen.imgix.net/jtci2pxwjczr/assets/5ice39g4.png?w=160\"/>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "996a1ee6-af8c-4beb-9e04-fb060d4b4302", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"# JSON - Get keys" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e994f0e6-af09-458f-a180-63fffb5ac4db", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**Tags:** #json #keys #get #data #python #library" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "7a45a28f-e1ea-4760-a4f8-89e45fc406e2", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**Author:** [Sriniketh Jayasendil](https://www.linkedin.com/in/sriniketh-jayasendil/)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "27a5939f-8e76-45bf-ab51-3cffeaf36a07", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**Last update:** 2023-10-04 (Created: 2023-10-04)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "cbcf7293-a094-4bd4-b978-54b665ebeb98", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**Description:** This notebook will list keys from a JSON file. It is usefull for organizations to quickly get the keys from a JSON file." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "bbaee1b1-4f0b-4eb3-ada1-a2a6921397a8", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**References:**\n", | ||
"- [JSON - Wikipedia](https://en.wikipedia.org/wiki/JSON)\n", | ||
"- [JSON - Tutorialspoint](https://www.tutorialspoint.com/json/index.htm)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0865e148-c5e2-463b-be04-d8952201493b", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Input" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "517d0b03-2aaf-451b-ab42-b592e5a346b4", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### Import libraries" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "807488b9-aa5f-409b-86c8-d4503d84ffc6", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import json" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c098320c-e510-4166-8ca6-87295c0484a3", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### Setup variables\n", | ||
"- `json_file`: path to the JSON file" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "28056cc6-c5d3-40c4-97c5-0a6082939f9b", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"json_file = \"data.json\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "df18418d-0c37-4472-9b78-887651a7e81c", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "923d603d-63a7-4ece-a8c4-4e7367001bde", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### Get keys from JSON file" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "b2e1717f-f343-407c-bd6b-40dee53c0b2c", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"Long description of the function: This function will open the JSON file and list all the keys from the file." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d8c55e27-6459-4fc0-8cbc-00273e0234b7", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Open JSON file\n", | ||
"with open(json_file) as f:\n", | ||
" data = json.load(f)\n", | ||
"# List keys\n", | ||
"keys = list(data.keys())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "7708ed08-1156-4815-982b-4291f94341c5", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Output" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c03ce1ee-6f08-4af3-8b62-c9e3a75c0ad1", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### Display result" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "15bcb58e-b3da-4913-bca6-c14aafe17725", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"print(keys)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c8447e99-a876-445f-b542-d45dbc2e5647", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"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.9.6" | ||
}, | ||
"widgets": { | ||
"application/vnd.jupyter.widget-state+json": { | ||
"state": {}, | ||
"version_major": 2, | ||
"version_minor": 0 | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |