J
J
Jsman2016-06-08 23:57:31
JavaScript
Jsman, 2016-06-08 23:57:31

How to pass object to json file?

Parsed the page and assembled an object from the ul > li elements. I launched my script in the browser through the developer panel, worked correctly, and now I have all the data I need in the object.
An object of this type:

var obj = {
  title : {
    name : {
      value : value,
    }
  }

  title : {
    name : {
      value : value,
    }
  }
}

Now the question is how can I save all this in json format. To save the entire tree hierarchy to a file ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2016-06-09
@SeniorDmitry

var a = document.createElement('a');
a.download = 'file_name.json';
var oUrl = URL.createObjectURL(new Blob([JSON.stringify(YOUR_JSON)], {type: 'application/octet-stream'}));
a.href = oUrl;
a.click();
delete a;
URL.revokeObjectURL(oUrl);

U
utyfua, 2016-06-09
@utyfua

You will get a syntax error in the "example": a comma is missing + key duplication
Poorly googled / yandexili. I asked a part of the question in Yandex: an object in json javascript. Here is for the lazy ones: itchief.ru/lessons/javascript/javascript-json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question