Skip to content

Instantly share code, notes, and snippets.

Last active November 21, 2021 19:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Firebase cloud firestore parser for gdscript (Godot Engine)
### Use example
const PROJECT_ID := "<your project ID>"
func get_document(path: String) -> void:
var url := FIRESTORE_URL + path
func _on_http_request_completed(result: int, response_code: int, headers: PoolStringArray, body: PoolByteArray) -> void:
if body and JSON.parse(body.get_string_from_ascii()).result:
var request_result := JSON.parse(body.get_string_from_ascii()).result as Dictionary
var res = firebase_firestore_parse(request_result)
### Parser
func firebase_firestore_parse(firebase_firestore_json:Dictionary):
var result:Dictionary
if "fields" in firebase_firestore_json.keys():
var fields:Dictionary = firebase_firestore_json["fields"]
for key in fields.keys():
return result
func _firebase_firestore_parse(value:Dictionary):
var keys := value.keys()
if keys.size()>0:
var key = keys.front()
if key == 'doubleValue':
return float(value[key])
elif key == 'integerValue':
return int(value[key])
elif key == 'arrayValue':
var tmp_array:Array = value[key]["values"]
var res_array:Array = []
for value in tmp_array:
return res_array
elif key == 'mapValue':
return firebase_firestore_parse(value[key])
return value[key]
return null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment