Sample code for 30+ languages & platforms
B4X

Firebase JSON Put and Patch

See more JSON Examples

Demonstrates how to apply Firebase put and patch events to a JSON database.

Chilkat B4X Downloads

B4X
Dim json1 As String = "{" & Chr(34) & "a" & Chr(34) & ": 1, " & Chr(34) & "b" & Chr(34) & ": 2}"

Dim json As ChilkatJsonObject
json.Initialize

'  Use Firebase delimiters for JSON paths.
json.DelimiterChar = "/"

json.Load(json1)
json.FirebasePut("/c", "{" & Chr(34) & "foo" & Chr(34) & ": true, " & Chr(34) & "bar" & Chr(34) & ": false}")
'  Output should be: {"a":1,"b":2,"c":{"foo":true,"bar":false}}
Log("1) " & json.Emit)

json.FirebasePut("/c", Chr(34) & "hello world" & Chr(34))
'  Output should be: {"a":1,"b":2,"c":"hello world"}
Log("2) " & json.Emit)

json.FirebasePut("/c", "{" & Chr(34) & "foo" & Chr(34) & ": " & Chr(34) & "abc" & Chr(34) & ", " & Chr(34) & "bar" & Chr(34) & ": 123}")
'  Output should be: {"a":1,"b":2,"c":{"foo":"abc","bar":123}}
Log("3) " & json.Emit)

'  Back to the original..
json.FirebasePut("/", "{" & Chr(34) & "a" & Chr(34) & ": 1, " & Chr(34) & "b" & Chr(34) & ": 2}")
Log("4) " & json.Emit)

json.FirebasePut("/c", "{" & Chr(34) & "foo" & Chr(34) & ": true, " & Chr(34) & "bar" & Chr(34) & ": false}")
json.FirebasePatch("/c", "{" & Chr(34) & "foo" & Chr(34) & ": 3, " & Chr(34) & "baz" & Chr(34) & ": 4}")
'  Output should be: {"a":1,"b":2,"c":{"foo":3,"bar":false,"baz":4}}
Log("5) " & json.Emit)

json.FirebasePatch("/c", "{" & Chr(34) & "foo" & Chr(34) & ": " & Chr(34) & "abc123" & Chr(34) & ", " & Chr(34) & "baz" & Chr(34) & ": {" & Chr(34) & "foo" & Chr(34) & ": true, " & Chr(34) & "bar" & Chr(34) & ": false}, " & Chr(34) & "bax" & Chr(34) & ": {" & Chr(34) & "foo" & Chr(34) & ": 200, " & Chr(34) & "bar" & Chr(34) & ": 400} }")
'  Output should be: {"a":1,"b":2,"c":{"foo":"abc123","bar":false,"baz":{"foo":true,"bar":false},"bax":{"foo":200,"bar":400}}}
Log("6) " & json.Emit)