import json
# Definining JSON object of Hellcat
hellcat_dict = {
"make": "Dodge",
"model": "Charger Hellcat",
"year": 2023,
"specs": {
"engine": "6.2L Supercharged V8",
"fuel_type": "Gasoline",
"horsepower": 707,
"torque": 650,
"transmission": "Automatic"
},
"features": [
"Bluetooth",
"Backup Camera"
],
"price": 69995.50,
"is_new": True
}
# Dumping JSON data to a string and outputting
json_string = json.dumps(hellcat_dict)
print(json_string)
{"make": "Dodge", "model": "Charger Hellcat", "year": 2023, "specs": {"engine": "6.2L Supercharged V8", "fuel_type": "Gasoline", "horsepower": 707, "torque": 650, "transmission": "Automatic"}, "features": ["Bluetooth", "Backup Camera"], "price": 69995.5, "is_new": true}
<IPython.core.display.Javascript object>
import json
# Definining JSON object of Hellcat
hellcat_dict = {
"make": "Dodge",
"model": "Charger Hellcat",
"year": 2023,
"specs": {
"engine": "6.2L Supercharged V8",
"fuel_type": "Gasoline",
"horsepower": 707,
"torque": 650,
"transmission": "Automatic"
},
"features": [
"Bluetooth",
"Backup Camera"
],
"price": 69995.50,
"is_new": True
}
# Printing the original dictionary
print(hellcat_dict)
# Increasing price
hellcat_dict["price"] = 9999999.99
print(hellcat_dict["price"])
# Making it not new anymore
hellcat_dict["is_new"] = False
print(hellcat_dict["is_new"])
# Adding a feature
hellcat_dict["features"] = ["Bluetooth", "Backup Camera", "Blind Spot Monitoring"]
print(hellcat_dict["features"])
# Newer model (setting to 2020)
hellcat_dict["year"] = 2020
print(hellcat_dict["year"])
# Changing the model
hellcat_dict["model"] = "Challenger Hellcat"
print(hellcat_dict["model"])
# Printing the final dictionary as a JSON string
print(json.dumps(hellcat_dict, indent=4))
{'make': 'Dodge', 'model': 'Charger Hellcat', 'year': 2023, 'specs': {'engine': '6.2L Supercharged V8', 'fuel_type': 'Gasoline', 'horsepower': 707, 'torque': 650, 'transmission': 'Automatic'}, 'features': ['Bluetooth', 'Backup Camera'], 'price': 69995.5, 'is_new': True}
9999999.99
False
['Bluetooth', 'Backup Camera', 'Blind Spot Monitoring']
2020
Challenger Hellcat
{
"make": "Dodge",
"model": "Challenger Hellcat",
"year": 2020,
"specs": {
"engine": "6.2L Supercharged V8",
"fuel_type": "Gasoline",
"horsepower": 707,
"torque": 650,
"transmission": "Automatic"
},
"features": [
"Bluetooth",
"Backup Camera",
"Blind Spot Monitoring"
],
"price": 9999999.99,
"is_new": false
}
%%javascript
// Definining JSON object of Hellcat
let hellcat_json =
{
"make": "Dodge",
"model": "Charger Hellcat",
"year": 2023,
"specs": {
"engine": "6.2L Supercharged V8",
"fuel_type": "Gasoline",
"horsepower": 707,
"torque": 650,
"transmission": "Automatic"
},
"features": [
"Bluetooth",
"Backup Camera"
],
"price": 69995.50,
"is_new": true,
};
console.log(hellcat_json);
// Increasing price
hellcat_json.price = 9999999.99;
console.log(hellcat_json.price);
// Making it not new anymore
hellcat_json.is_new = false;
console.log(hellcat_json.false);
// Adding a feature
hellcat_json.features = ["Bluetooth", "Backup Camera", "Blind Spot Monitoring"];
console.log(hellcat_json.features);
// Newer model
hellcat_json.year = 2020;
console.log(hellcat_json.year);
// Changing the model
hellcat_json.model ="Challenger Hellcat";
console.log(hellcat_json.model);
// Output the final object as a JSON string
console.log(JSON.stringify(hellcat_json));
<IPython.core.display.Javascript object>