Skip to content

Instantly share code, notes, and snippets.

@aveek22
Created December 28, 2020 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aveek22/c7fc11b226504420c6ec980534a94ba5 to your computer and use it in GitHub Desktop.
Save aveek22/c7fc11b226504420c6ec980534a94ba5 to your computer and use it in GitHub Desktop.
# 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