Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON: Add Get keys #2250

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 267 additions & 0 deletions JSON/JSON_Get_keys.ipynb
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
}
Loading