Skip to content

capaj/moment-json-parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moment.js JSON Parser

Date parsing extensions for the JavaScript JSON parser to provide moment objects from JSON.parse()####

This small JavaScript library provides for automatically parsing JSON date strings to moment objects as part of regular JSON parsing. You can parse either individual date values or complex objects containing dates and have them automatically turned into moments, unlike the default JSON parser behavior of parsing to ISO 8601 date strings.

You can either manually run the date parsing or replace the JSON parser for the global scope to force all JSON operations to parse dates automatically, including those by other frameworks such as jQuery, angularJS etc.

This library is a fork or original which works with moment.js rather than with raw date.

Original article

Usage

Install

npm i moment-json-parser -S
#or with JSPM
jspm install moment-json-parser

Use as a function which you just require

var jsonParser = require('../moment-json-parser');

or override the default JSON.parse

require('moment-json-parser').overrideDefault();
// JSON.parse gives you moments !!!
// demo:
var a = {a:moment()};
var b = JSON.parse(JSON.stringify(a));
var c = jsonParser(JSON.stringify(a));
console.log(b.a, c.a); //still moment objects

you can also revert back to default JSON.parse

require('moment-json-parser').overrideDefault(false);
// JSON.parse gives you only strings :-(

About

Date parsing extensions for the JavaScript JSON parser to provide moment objects directly from JSON.parse()

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%