- Meteor - Best Practices
- Meteor - ToDo App
- Meteor - Running on mobile
- Meteor - Deployment
- Meteor - Structure
- Meteor - Publish & Subscribe
- Meteor - Package.js
- Meteor - Methods
- Meteor - Accounts
- Meteor - Sorting
- Meteor - Security
- Meteor - Assets
- Meteor - Email
- Meteor - HTTP
- Meteor - EJSON
- Meteor - Timers
- Meteor - Blaze
- Meteor - Check
- Meteor - Core API
- Meteor - Packages
- Meteor - Tracker
- Meteor - Session
- Meteor - Events
- Meteor - Forms
- Meteor - Collections
- Meteor - Templates
- Meteor - First Application
- Meteor - Environment Setup
- Meteor - Overview
- Meteor - Home
Meteor Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Meteor - EJSON
EJSON is an extension of JSON syntax that supports Date and Binary types.
Install EJSON
To install EJSON package, we need to add it from the command prompt window.
C:UsersusernameDesktopmeteorApp>meteor add ejson
Date Example
We can deseriapze the date using the parse method.
if (Meteor.isCpent) { var myEjsonDate = {"$date": 1455029631493} ; var myDate = EJSON.parse(myEjsonDate); console.log(myDate); }
The console will log the correct date value.
Binary Example
The same can be appped to binary types.
if (Meteor.isCpent) { var myEjsonBinary = {"$binary": "c3VyZS4="} ; var myBinary = EJSON.parse(myEjsonBinary); console.log(myBinary); }
You can see that the console is logging new deseriapzed value.
Stringify
We can seriapze an object using the stringify method. This is the reversed process from the example above.
if (Meteor.isCpent) { var myObject = { myDate : new Date(), myBinary : new Uint8Array([115, 117, 114, 101, 46]) } var myEjosnData = EJSON.stringify(myObject); console.log(myEjosnData); }
We can see our new values in the console.
Sr.No. | Method & Details |
---|---|
1 | EJSON.parse(string) Used for parsing a string into EJSON value. |
2 | EJSON.stringify(value) Used for seriapzing a value to the string. |
3 | EJSON.fromJSONValue(value) Used for deseriapzing an EJSON value from JSON. |
4 | EJSON.toJSONValue(value) Used for seriapzing an EJSON value into JSON. |
5 | EJSON.equals(value1, value2) Used for comparing if two values are equal. |
6 | EJSON.clone(value) Used for returning a deep copy of the value. |
7 | EJSON.newBinary Used for assigning a binary data that EJSON can seriapze. |
8 | EJSON.isBinary(x) Used for checking if the value is a binary data. |
9 | EJSON.addType(name, factory) Used for creating a custom EJSON type. |
10 | customType.typeName() Used for returning a name of the custom type. |
11 | customType.toJSONValue() Used for seriapzing custom types. |
12 | customType.clone() Used for returning a deep copy of the custom type. |
13 | customType.equals(otherValue) Used for comparison between the custom type value and other value. |