Search code examples
javascriptjsontypescriptesri

Turn TypeScript object into JSON string


I'm trying to initialize an object in TypeScript which requires a JSON string for the options parameter. To be precise it is the object here. The parameter is required to be a JSON string and not an object.

Is there a way to create a JSON string from a TypeScript object without it being a manual process?


Solution

  • Just use JSON.stringify(object). It's built into Javascript and can therefore also be used within Typescript.