python object to json
import json
x = '{ "name":"John", "age":30, "city":"New York"}'
y = json.loads(x)
print(y["age"]) jsonStr = json.dumps(myobject.__dict__)import json
class Laptop:
name = 'My Laptop'
processor = 'Intel Core'
#create object
laptop1 = Laptop()
laptop1.name = 'Dell Alienware'
laptop1.processor = 'Intel Core i7'
#convert to JSON string
jsonStr = json.dumps(laptop1.__dict__)
#print json string
print(jsonStr)# a Python object (dict):
x = {
"name": "John",
"age": 30,
"city": "New York"
}
# convert into JSON:
y = json.dumps(x)
Also in JavaScript:
- get current url react router
- php generate random string fixed length
- create dynamic fields in react
- check unique object in array javascript site:stackoverflow.com
- javascript is int in array
- sort javascript array
- js money format br
- convert integer month to string month react native
- FizzBuzz
- detect if two line segments intersect each other javascript
- mongodb distancefield to kms
- array javascript
- how will it look when there is a container inside a a row bootstrap
- The target origin provided ('https://www.youtube.com') does not match the recipient window's origin ('http://localhost')
- javascript on input change
- javascript check if object is empty
- help source code discord.js
- jquery select2 multiple select all
- json placeholder api
- find length of longest string in array javascript
- how to sent react from data in mongodb
- jquery remove disabled property from button
- how to validate an email address in javascript
- how to add a variable in js