Skip to content
Advertisement

How to parse JSON string in Typescript

Is there a way to parse strings as JSON in TypeScript?

For example in JavaScript, we can use JSON.parse(). Is there a similar function in TypeScript?

I have a JSON object string as follows:

JavaScript

Advertisement

Answer

TypeScript is (a superset of) JavaScript, so you just use JSON.parse as you would in JavaScript:

JavaScript

Only that in TypeScript you can also have a type for the resulting object:

JavaScript

(code in playground)

Advertisement