2

Just like the title says, I need to save json in memory data. I want to be able to trigger this from onlick event on some dom object.

I want to save the data on the users computer as if they were downloading this file. Saving as text is fine.

There is no server to talk to.

UPDATE:

http://jsfiddle.net/adouga/GpcAt/1/

I am getting

TypeError: cyclic object value var json1 = JSON.stringify(mydata);

UPDATE: The cyclic error was happening because fullcalendar objects have it's own custom properties and nested objects. So I iterate over the returned object array and copy objects only with my properties to another array which can be stringified just fine

http://jsfiddle.net/adouga/GpcAt/2/

I think this might do the trick of copying to clipboard.

http://www.steamdev.com/zclip/

  • In memory where? on the users computer? You can probably do that with a cookie or local storage, but you'll have to convert your json to a string first. A little more information about what it is you are trying to do, how you intend to use it, and what you have tried so far would be helpful! – adeneo Aug 10 '12 at 00:18

1 Answers1

2

To save in the browser you can just use localStorage. To serve the json as text you can do with HTML5 File API. Check this discusion: Create Text file from String using JS and html5

Community
  • 1
  • 1
Rafael Motta
  • 2,328
  • 2
  • 19
  • 18
  • I'll try the solution in the link and let you know. –  Aug 10 '12 at 00:30
  • I am getting WebKitBlobBuilder is undefined. I guess IE8 does not support this. –  Aug 10 '12 at 00:37
  • IE does not support File API. To serve this file crossbrowser, you should use a server side solution. – Rafael Motta Aug 10 '12 at 00:47
  • I can just save the json data as a string into some hidden text area and then do a copy to clipboard. It's just text after all. –  Aug 10 '12 at 01:11
  • So just use JSON.stringify(json) and localStorage.setItem('myJsonKey' myjson) – Rafael Motta Aug 10 '12 at 01:20