Created
December 28, 2020 21:48
-
-
Save aveek22/c7fc11b226504420c6ec980534a94ba5 to your computer and use it in GitHub Desktop.
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
# imports the Pandas library to work in python | |
import pandas as pd | |
# assign the JSON data to a variable | |
json_data = """{ | |
"data": [ | |
{ | |
"type": "articles", | |
"id": "1", | |
"attributes": { | |
"title": "Working with JSON Data in python", | |
"description": "This article explains the various ways to work with JSON data in python.", | |
"created": "2020-12-28T14:56:29.000Z", | |
"updated": "2020-12-28T14:56:28.000Z" | |
}, | |
"author": { | |
"id": "1", | |
"name": "Aveek Das" | |
} | |
} | |
] | |
}""" | |
# Print the datatype of the original variable before deserialization | |
print(f'Datatype before deserialization: {str(type(json_data))}') | |
print("\n") | |
# Deserialize the JSON to a python dictionary object | |
new_data = pd.read_json(json_data, orient="records") | |
# Print the datatype of the new variable after deserialization | |
print(f'Datatype after deserialization: {str(type(new_data))}') | |
print(new_data) | |
print("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment