1.0.2 • Published 1 year ago

firestore-document-parser v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

firestore-document-parser

Parse the Firestore REST API JSON into a useable JS object

Installation

  // Install with NPM
  npm install firestore-document-parser --save
  // or Install with Yarn
  yarn add firestore-document-parser

Examples

  import { parser } from "firestore-document-parser";

  const projectID = "PROJECT_ID";
  const key = "API_KEY";
  const doc = "DOCUMENT";
  const url = `https://firestore.googleapis.com/v1beta1/projects/${projectID}/databases/(default)/documents/${doc}?key=${key}`;
  
  fetch(url)
    .then(response => response.json())
    .then(json => parser(json))
    .then(json => console.log(json));

Data Structure

The Firestore JSON returned in the REST API, uses value type as keys. This can be difficult to work with since you have to know the data type prior getting the value. The firestore-document-parser removes this barrier for you.

JSON response from Firestore

{
	"player": {
		"mapValue": {
			"fields": {
				"name": {
					"stringValue": "steve"
				},
				"health": {
					"integerValue": "100"
				},
				"alive": {
					"booleanValue": true
				}
			}
		}
	},
	"level": {
		"integerValue": "7"
	}
}

JSON parsed with firestore-document-parser

{
	"player": {
		"name": "steve",
		"health": 100,
		"alive": true
	},
	"level": 7
}
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

2 years ago