https://github.com/mustaddon/json-date-fix
JSON serialization/deserialization fix for Date objects
https://github.com/mustaddon/json-date-fix
date-formatting dateonly datetime javascript json-deserialization json-parse json-parsing
Last synced: 5 months ago
JSON representation
JSON serialization/deserialization fix for Date objects
- Host: GitHub
- URL: https://github.com/mustaddon/json-date-fix
- Owner: mustaddon
- License: mit
- Created: 2022-08-28T16:00:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-19T19:59:39.000Z (8 months ago)
- Last Synced: 2024-12-02T04:27:54.151Z (6 months ago)
- Topics: date-formatting, dateonly, datetime, javascript, json-deserialization, json-parse, json-parsing
- Language: JavaScript
- Homepage:
- Size: 46.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json-date-fix [](https://www.npmjs.com/package/json-date-fix)
JSON serialization/deserialization fix for Date objects```js
import 'json-date-fix' // need once at the root of your app// serialization fix: preserve timezone information
console.log(JSON.stringify(new Date(2023, 5, 7)));// deserialization date-string to Date object
console.log(JSON.parse('"2023-06-07T00:00:00.000+03:00"'));//// Console output:
// "2023-06-07T00:00:00.000+03:00"
// Wed Jun 07 2023 00:00:00 GMT+0300 (Moscow Standard Time)
```Example with DateOnly format support
```js
import jsonDateFix from './index.js';
jsonDateFix({ dateonly: true }); // enable dateonly format ('yyyy-MM-dd') analysis// deserialization dateonly-string to Date object
console.log(JSON.parse('"2023-06-07"'));//// Console output:
// Wed Jun 07 2023 00:00:00 GMT+0300 (Moscow Standard Time)
```