-2

There is a JSON data stored in a variable in javascript. I have to stored it in other file named .json.How can I do it.Json data is something like this :

{
  "method":"get",
  "class":"form-horizontal",
  "html":[{
              "type":"div",
              "class":"form-group",
              "id":"input_Name",
              "html":[{
                       "type":"label",
                       "class":"control-label col-sm-2",
                       "for":"input_Name",
                       "html":"Name"},
                      {
                       "type":"div",
                       "class":"col-sm-10",
                       "html":[{
                               "type":"text",
                               "class":"form-control",
                               "name":"input_Name",
                               "id":"input_Name",
                               "placeholder":"user@example.com"
                              }]
                      }]
        }]
}
Jeet
  • 47
  • 1
  • 6

1 Answers1

3

Use saveAs(blob, filename) :

var blob = new Blob([JSON.stringify(data)], {type: "text/plain;charset=utf-8"});
saveAs(blob, "data.json");

JSFiddle: http://jsfiddle.net/2wcew2xs/

Iter Ator
  • 8,226
  • 20
  • 73
  • 164