How to export localstorage using JSON

14,202 views
Skip to first unread message

Derek 囧

unread,
Sep 14, 2010, 8:38:10 PM9/14/10
to Chromium-extensions
I want to make my extension's data "exportable" using the json format.
But bow to export localStorage using JSON?

Thanks

Derek ;)

UVL

unread,
Sep 15, 2010, 3:29:02 AM9/15/10
to Chromium-extensions
Agree, would be cool to be able to create downloadable files on the
fly.

PhistucK

unread,
Sep 15, 2010, 3:45:18 AM9/15/10
to Derek 囧, Chromium-extensions
Mmm.. what about JSON.stringify(localStorage)? Seems to work for me.
PhistucK




--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Derek 囧

unread,
Sep 15, 2010, 7:15:59 PM9/15/10
to Chromium-extensions
Oh wow, thanks, it works!
But how can I import the data again from JSON.stringify(localStorage)?

Derek

v v ...view it... v v
> Mmm.. what about JSON.stringify(localStorage)? Seems to work for me.
> ☆*PhistucK*
>
>
>
>
>
>
>
> On Wed, Sep 15, 2010 at 02:38, Derek 囧 <derek1...@gmail.com> wrote:
> > I want to make my extension's data "exportable" using the json format.
> > But bow to export localStorage using JSON?
>
> > Thanks
>
> > Derek ;)
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>
> > .

Antony Sargent

unread,
Sep 15, 2010, 8:23:07 PM9/15/10
to Derek 囧, Chromium-extensions
Something like this might work:

var data = JSON.parse(previously_exported_string);
for (var key in data) {
  localstorage[key] = data[key];
}


To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Derek 囧

unread,
Sep 15, 2010, 9:36:35 PM9/15/10
to Chromium-extensions
It works again! Thanks!

Derek

> Something like this might work:
>
> var data = JSON.parse(previously_exported_string);
> for (var key in data) {
>   localstorage[key] = data[key];
>
>
>
>
>
>
>
> }
> On Wed, Sep 15, 2010 at 4:15 PM, Derek 囧 <derek1...@gmail.com> wrote:
> > Oh wow, thanks, it works!
> > But how can I import the data again from JSON.stringify(localStorage)?
>
> > Derek
>
> >  v v ...view it... v v
> > > Mmm.. what about JSON.stringify(localStorage)? Seems to work for me.
> > > ☆*PhistucK*
>
> > > On Wed, Sep 15, 2010 at 02:38, Derek 囧 <derek1...@gmail.com> wrote:
> > > > I want to make my extension's data "exportable" using the json format.
> > > > But bow to export localStorage using JSON?
>
> > > > Thanks
>
> > > > Derek ;)
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Chromium-extensions" group.
> > > > To post to this group, send email to chromium-extensi...@chromium.org.
> > > > To unsubscribe from this group, send email to
> > > > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>
> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>
Message has been deleted

Derek 囧

unread,
Sep 15, 2010, 9:40:10 PM9/15/10
to Chromium-extensions
At first I thought it would be very complex but actually it's just a
few things int it.
Wow amazing.

Derek

>
>
>
>
>
>
> > Something like this might work:
>
> > var data = JSON.parse(previously_exported_string);
> > for (var key in data) {
> >   localstorage[key] = data[key];
>
> > }
> > On Wed, Sep 15, 2010 at 4:15 PM, Derek 囧 <derek1...@gmail.com> wrote:
> > > Oh wow, thanks, it works!
> > > But how can I import the data again from JSON.stringify(localStorage)?
>
> > > Derek
>
> > >  v v ...view it... v v
> > > > Mmm.. what about JSON.stringify(localStorage)? Seems to work for me.
> > > > ☆*PhistucK*
>
> > > > On Wed, Sep 15, 2010 at 02:38, Derek 囧 <derek1...@gmail.com> wrote:
> > > > > I want to make my extension's data "exportable" using the json format.
> > > > > But bow to export localStorage using JSON?
>
> > > > > Thanks
>
> > > > > Derek ;)
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "Chromium-extensions" group.
> > > > > To post to this group, send email to chromium-extensi...@chromium.org.
> > > > > To unsubscribe from this group, send email to
> > > > > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>
> > > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>

TobiFromBavaria

unread,
Sep 27, 2010, 1:58:23 PM9/27/10
to Chromium-extensions
Keep in mind that localStorage.getItem("length") returns the value for
the key "length", while localStorage["length"] returns the number of
key/value pairs. If you had a key "length" in your Storage, you will
lose it with the code posted here.

PhistucK

unread,
Sep 27, 2010, 2:17:53 PM9/27/10
to TobiFromBavaria, Jeremy Orlow, Chromium-extensions
Is that a bug?
If I add "length" to localStorage using setItem and use JSON.stringify on localStorage, it consists of "length" and it has a different value than the one I originally put (in my trial, it was the only key I added, with a value of 8 and stringify created this string - {"length": 1} instead).
PhistucK




--

Jeremy Orlow

unread,
Sep 27, 2010, 2:32:39 PM9/27/10
to PhistucK, TobiFromBavaria, Chromium-extensions
I don't fully understand how JSON.stringify works or the example you're giving here, but...

TobiFromBavaria's understanding is that of mine when I worked on the code (and I believe what most vendors do), but a recent message has brought this into question.  (I still haven't gotten a response to http://www.mail-archive.com/public-...@w3.org/msg09879.html though.)  Personally I think not allowing length and such to be overridden would probably be more clear.

J

Tarek Faham

unread,
Aug 11, 2016, 1:22:00 PM8/11/16
to Chromium-Extensions-Announce, dere...@gmail.com
Thank you so much useful.

How I can save the result string from  JSON.stringify(localStorage) to a local file? Basically, a dwonload effect that will allow the user to save the string to a local file.

Appreciate your feedback.

Tarek

On Wednesday, 15 September 2010 03:45:18 UTC-4, PhistucK wrote:
Mmm.. what about JSON.stringify(localStorage)? Seems to work for me.
PhistucK



On Wed, Sep 15, 2010 at 02:38, Derek 囧 <dere...@gmail.com> wrote:
I want to make my extension's data "exportable" using the json format.
But bow to export localStorage using JSON?

Thanks

Derek ;)

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extensions+unsub...@chromium.org.

PhistucK

unread,
Aug 11, 2016, 2:24:28 PM8/11/16
to Tarek Faham, Chromium-Extensions-Announce, Derek Leung
Not really the place to ask this, but since I like those little hacks ;) something like...
HTML -
<a class="link-to-download" href="download" download="export.json">Export</a>
JavaScript -
document.querySelector(".link-to-download").addEventListener(
 function ()
 {
  this.href = "data:application/json," + escape(JSON.stringify(localStorage));
 });



PhistucK

On Thu, Aug 11, 2016 at 8:22 PM, Tarek Faham <tare...@gmail.com> wrote:
Thank you so much useful.

How I can save the result string from  JSON.stringify(localStorage) to a local file? Basically, a dwonload effect that will allow the user to save the string to a local file.

Appreciate your feedback.

Tarek

On Wednesday, 15 September 2010 03:45:18 UTC-4, PhistucK wrote:
Mmm.. what about JSON.stringify(localStorage)? Seems to work for me.
PhistucK



On Wed, Sep 15, 2010 at 02:38, Derek 囧 <dere...@gmail.com> wrote:
I want to make my extension's data "exportable" using the json format.
But bow to export localStorage using JSON?

Thanks

Derek ;)

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.

To unsubscribe from this group, send email to chromium-extensions+unsubscribe...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-extensions@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/05b4dc0a-4b0b-4cde-8c61-d3725ad09493%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Wolf War

unread,
Aug 12, 2016, 1:30:46 AM8/12/16
to PhistucK, Tarek Faham, Chromium-Extensions-Announce, Derek Leung



PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsubscribe...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-extensions@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.

Tarek Faham

unread,
Aug 12, 2016, 1:00:47 PM8/12/16
to Chromium-Extensions-Announce, phis...@gmail.com, tare...@gmail.com, dere...@gmail.com
Thank you so much ... This is very close to what I am looking for.

One more question if you don't mind.

Is it possible to develop off-line application using HTML5 and AngularJS or similar framework? So the sequence would be something like:

- Connect online
- Start the application: form filling
- Take work off-line
- Be able to continue form filling offline: open/save/load/
- When connected online, then will be able to submit to server.

I appreciate your feedback on the above.

Tarek


PhistucK


To unsubscribe from this group, send email to chromium-extensions+unsub...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.

PhistucK

unread,
Aug 12, 2016, 7:23:14 PM8/12/16
to Tarek Faham, Chromium-Extensions-Announce, Derek Leung
I do mind, actually. This is completely out of scope for this group.

(Regardless, the answer is yes. For details, search the web.)


PhistucK



PhistucK


To unsubscribe from this group, send email to chromium-extensions+unsubscribe...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsubscribe...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsubscribe...@chromium.org.
Reply all
Reply to author
Forward
0 new messages