Look at built-in JSONEncoder class.