Run
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)
Output