turn typescript object into json string

user1567453 picture user1567453 · Feb 12, 2016 · Viewed 113.1k times · Source

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 options parameter is required to be a JSON string and not an object for initializing the dijit.

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

Please DO NOT link any questions which don't specifically say "TypeScript" as this question specifically relates to TypeScript. While a derivative of JavaScript the way that you write code is different and therefore this is the only post asking this question currently relating to TypeScript.

Answer

Luka Jacobowitz picture Luka Jacobowitz · Feb 12, 2016

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