Lilou
Lilou

Reputation: 1

Quasar export table to json

I am studying quasar at the moment, and I want to know how to export a table to JSon. I have data in JSonimported and I want to get output in JSon too.

Now I'm using JSON.stringify to get data of my table, but that gives all data in a single line in JSon.

Here's a piece of my code in quasar :

exportTable() { const status = exportFile('table.json', JSON.stringify(this.data), 'text/json')}

and it gives me :

[{"Name":"xxx","Adress":"xxx","Zip code":"xxx"},{"Name":"yyy","Adress":"yyy","Zip code":"yyy"}]

What I want to output :

[{
"Name":"xxx",
"Adress":"xxx",
"Zip code":"xxx"
},
{
"Name":"yyy",
"Adress":"yyy",
"Zip code":"yyy"
}]

How can I get this ?

Upvotes: 0

Views: 686

Answers (1)

Meir
Meir

Reputation: 45

If I understood correctly, you want to use:

JSON.stringify(this.data, null, 4)

Where the last argument (4) is the spacing you desire.

You can have a look at JSON.stringify official documentation

const data = [{"Name":"xxx","Adress":"xxx","Zip code":"xxx"},{"Name":"yyy","Adress":"yyy","Zip code":"yyy"}]

console.log(JSON.stringify(data, null, 4))

Upvotes: 1

Related Questions