Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6833905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:02:33+00:00 2026-05-26T23:02:33+00:00

For anyone interested, I ended up building a localstorage with expirations script here, http://plugins.jquery.com/project/localcache

  • 0

For anyone interested, I ended up building a “localstorage with expirations” script here, http://plugins.jquery.com/project/localcache

What I’m doing: building an extension for Storage, so that the user can do this:

localStorage.setThing(key, value)

and the user can do the following:

localStorage.setThing("key1", 1)
localStorage.setThing("key2", "this is a string")
localStorage.setThing("key3", { prop1: "this is a json obj" })

In my setThing method, I’m checking for the typeof for value, and if typeof value == "object", I’m storing it as localStorage.setItem(key, JSON.stringify(value))

On the getThing method, I know that the value that makes it into localStorage is always going to be a string. So, how can I do this?

var val = localStorage.getItem("key3")
if (val is a previously JSON.stringify'd object) // <-- ??
    return JSON.parse(val)

Do I need to do a regex check on val, and if so, does anyone have a pattern handy which tells me if a string is really a JSON.stringify’d object?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:02:34+00:00Added an answer on May 26, 2026 at 11:02 pm

    Another option is to store an object {isJsonObj:true, jsonObj: jsonObj}, and check the type is Object, and isJsonObj is true. If either of those are false, then it isn’t a json obj (this means you don’t have to parse). I realise this means you won’t always have a string in there, but it makes it easy to test, and won’t carry a large amount of overhead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question follows my previous question here in case anyone is interested. I am
SQL newbie here :) Here are my tables if anyone's interested. AHH, cant post
FOR ANYONE INTERESTED: I have implemented the code for the behaviour I am looking
Interested if anyone has used VSTS Database Edition extensively and, if so, which features
I am interested to know whether anyone has written an application that takes advantage
Anyone have suggestions for security auditing of an .NET Web Application? I'm interested in
Anyone know of a good beginners tutorial for Turbogears 2? I'm particularly interested in
I'm interested in grabbing the EPG data from DVB-T streams. Does anyone know of
Can anyone recommend good simulation software for mobile devices? I am most interested in
Does anyone know any resources (books/websites/whatever) related to parsing. I'm not so much interested

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.