Skip to content

Instantly share code, notes, and snippets.

@polotek
Forked from mikeal/gist:2504336
Created January 25, 2018 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polotek/7d0a9238d2f913fc7c5dd9bf51db2a62 to your computer and use it in GitHub Desktop.
Save polotek/7d0a9238d2f913fc7c5dd9bf51db2a62 to your computer and use it in GitHub Desktop.
Date parsing JSON
JSON._dateReviver = function (k,v) {
if (v.length !== 24 || typeof v !== 'string') return v
try {return new Date(v)}
catch(e) {return v}
}
JSON.parseWithDates = function (obj) {
return JSON.parse(obj, JSON._dateReviver);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment