Navigate back to the homepage

how to stringify json object in typescript?

Infinitbility
TypeScript
July 20th, 2022 · 1 min read
how to stringify json object in typescript?

Stringify JSON object in typescript

To stringify json object in typescript, use JSON.stringify() it will convert your json object to json string.

The JSON.stringify() method converts a JavaScript object or value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.

1interface domain {
2 name: string,
3 domain: string,
4}
5
6const arr: Array<domain> = [
7 {
8 name: "infinitbility",
9 domain: "infinitbility.com"
10 },
11 {
12 name: "aguidehub",
13 domain: "aguidehub.com"
14 }
15 ];
16
17// ✅ Convert array of object to string
18const str: string = JSON.stringify(arr);
19console.log(str); // 👉️ '[{"name":"infinitbility","domain":"infinitbility.com"},{"name":"aguidehub","domain":"aguidehub.com"}]'

Note: The toString() and join() method only work for array of string, number not object.

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to convert array to string in typescript?

how to convert array to string in typescript?

TypeScript, convert array to string example with step-by-step guide.

July 19th, 2022 · 1 min read
how to remove space from string in typescript?

how to remove space from string in typescript?

TypeScript, add remove space from string example with step-by-step guide.

July 18th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]