Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🗃 JSON parser and builder for ESP8266, ESP32, Teensy3.x and Teensy4.x, SAM, SAMD and STM32 (128 k flash or more)

License

NotificationsYou must be signed in to change notification settings

mobizt/FirebaseJson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The easiest Arduino library JSON parser, builder and editor.

FirebaseJson is the easiest JSON manipulation library to parse or deserialize complex or nested JSON objects and arrays.

The new version of library is now powered by cJSON.

Able to Parse, create and edit the simple or complex (depth nested) JSON object by just specify the relative node/element path.

This library supports any Arduino based MCU, ESP8266, ESP32, Teensy 3.x (ARM-Cortext M4) and Teensy 4.x (ARM-Cortext M7), AVR, SAMD, STM32 (128K flash or more) Arduino Nano RP2040 Connect, RaspberryPi Pico are recommended.

Tested Devices

  • ESP8266
  • ESP32
  • Teensy 3.6
  • Teensy 4.0
  • Teensy 4.1
  • Arduino MKR WiFi 1010
  • Arduino MKR1000 WIFI
  • STM32F103C
  • STM32FF407
  • RP2040 Pico

Features

  • Non-recursive parsing

  • Parse, Create and Edit JSON object directly by just specify the relative path to the node element

  • Prettify JSON string

Dependencies

For ESP8266 and ESP32, the library requiresESP8266 Core SDK version 2.4.0 and above or ESP32 Core SDK version 1.0.2 and above.

To install the ESP8266 Core SDK from Arduino IDE, ESP8266/ESP32 Core SDK can be installed throughBoards Manager.

For PlatfoemIO IDE, ESP8266 Core SDK can be installed throughPIO Home >Platforms >Espressif 8266 or Espressif 32.

For Teensy 3.x and Teensy 4.x,Teensyduino was required and can be downloaded.

Installation

For Arduino IDE, from Github repo, selectClone or download dropdown at the top of repository, selectDownload ZIP

From Arduino IDE, select menuSketch ->Include Library ->Add .ZIP Library....

ChooseFirebaseJson-master.zip that previously downloaded.

Go to menuFiles ->Examples ->FirebaseJson-master and choose one from examples.

For PlatformIO IDE, using the following command.

pio lib install "FirebaseJson"

Or at PIO Home -> Library -> Registry then search FirebaseJson.

IDE Configuaration for ESP8266 MMU - Adjust the Ratio of ICACHE to IRAM

Arduino IDE

When you update the ESP8266 Arduino Core SDK to v3.0.0, the memory can be configurable from Arduino IDE board settings.

By default MMUoption 1 was selected, the free Heap can be low and may not suitable for the SSL client usage in this library.

To increase the Heap, choose the MMUoption 3, 16KB cache + 48KB IRAM and 2nd Heap (shared).

Arduino IDE config

To use external Heap from 1 Mbit SRAM 23LC1024, choose the MMUoption 5, 128K External 23LC1024.

MMU VM 128K

To use external Heap from PSRAM, choose the MMUoption 6, 1M External 64 MBit PSRAM.

The connection between SRAM/PSRAM and ESP8266

23LC1024/ESP-PSRAM64                ESP8266CS (Pin 1)                          GPIO15SCK (Pin 6)                         GPIO14MOSI (Pin 5)                        GPIO13MISO (Pin 2)                        GPIO12/HOLD (Pin 7 on 23LC1024 only)      3V3Vcc (Pin 8)                         3V3Vcc (Pin 4)                         GND

More about MMU settings.https://arduino-esp8266.readthedocs.io/en/latest/mmu.html

PlatformIO IDE

By default the balanced ratio (32KB cache + 32KB IRAM) configuration is used.

To increase the heap,PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED build flag should be assigned in platformio.ini.

[env:d1_mini]platform = espressif8266build_flags = -D PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHAREDboard = d1_miniframework = arduinomonitor_speed = 115200

And to use external Heap from 1 Mbit SRAM 23LC1024 and 64 Mbit PSRAM,PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_128K andPIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_1024K build flags should be assigned respectively.

The supportedd MMU build flags in PlatformIO.

  • PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48

    16KB cache + 48KB IRAM (IRAM)

  • PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED

    16KB cache + 48KB IRAM and 2nd Heap (shared)

  • PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM32_SECHEAP_NOTSHARED

    16KB cache + 32KB IRAM + 16KB 2nd Heap (not shared)

  • PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_128K

    128K External 23LC1024

  • PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_1024K

    1M External 64 MBit PSRAM

  • PIO_FRAMEWORK_ARDUINO_MMU_CUSTOM

    Disables default configuration and expects user-specified flags

In ESP8266, to use PSRAM/SRAM for internal memory allocation which you can config to use it viaFBJS_Config.h with this macro.

#defineFIREBASEJSON_USE_PSRAM

Test code for MMU

#include<Arduino.h>#include<umm_malloc/umm_heap_select.h>voidsetup() {  Serial.begin(115200);  HeapSelectIram ephemeral;  Serial.printf("IRAM free: %6d bytes\r\n", ESP.getFreeHeap());  {    HeapSelectDram ephemeral;    Serial.printf("DRAM free: %6d bytes\r\n", ESP.getFreeHeap());  }  ESP.setExternalHeap();  Serial.printf("External free: %d\n", ESP.getFreeHeap());  ESP.resetHeap();}voidloop() {// put your main code here, to run repeatedly:}

PSRAM support in ESP32

The library supports PSRAM in ESP32 via macro, in fileFBJS_Config.h

#define FIREBASEJSON_USE_PSRAM

To enable PSRAM in ESP32 module with on-board PSRAM chip, in Arduino IDE

Enable PSRAM in ESP32

In PlatformIO in VSCode IDE, add the following build_flags in your project's platformio.ini file

build_flags = -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue

*When config the IDE or add the build flags to use PSRAM in the ESP32 dev boards that do not have on-board PSRAM chip, your device will be crashed (reset).

In ESP32, to use PSRAM/SRAM for internal memory allocation which you can config to use it viaFBJS_Config.h with this macro.

#defineFIREBASEJSON_USE_PSRAM

Usages

FirebaseJson usages are so simple as you read, store and update(edit) the JSON node in Firebase RTDB.

Since you declare the FirebaseJson or FirebaseJsonArray object, use the functionssetJsonData,setJsonArrayData,add,set andremove to build or edit the JSON/Array object and useget to parse the node's contents.

Defined the relative path of the specific node toadd,set,remove andget functions to add, set, remove and get its contents.

FunctionFirebaseJson.setJsonData is to deserialize the JSON string to JSON object.

In addition, functionFirebaseJson.readFrom can be used to read the streaming JSON contents from WiFi/Ethernet Client, File and Harware Serial and serialize it as the streaming content contains valid JSON data.

FunctionFirebaseJson.add is used to add the new node with the contents e.g. String, Number (int and double), Boolean, Array and Object to the defined node.

FunctionFirebaseJson.set is used for edit, overwrite, create new (if not exist) node with contents e.g. String, Number (int and double), Boolean, Array and Object at the defined relative path and node.

FunctionFirebaseJson.get is used for parsing or deserializee the JSON object and array. The deserialized or parsed result will keep in FirebaseJsonData object which can be casted to any type of value or variable e.g string, bool, int, float, double by usingFirebaseJsonData.to<type>.

The casting from FirebaseJsonData to FirebaseJson and FirebaseJsonArray objects is different, by usingFirebaseJsonData.getJSON(FirebaseJson) andFirebaseJsonData.getArray(FirebaseJsonArray).

FunctionFirebaseJson.remove is used to remove the node and all its children's contents at the defined relative path and node.

FunctionFirebaseJson.toString is used for serializeing the JSON object to writable objects e.g. char array, Arduino String, C/C++ string, WiFi/Ethernet Client and Hardware/Software Serial.

FunctionFirebaseJson.serializedBufferLength is used for calculating the serialized buffer size that required for reserved buffer in serialization.

FunctionFirebaseJson.responseCode is used to get the http code response header while read the WiFi/Ethernet Client usingFirebaseJson.toString.

FunctionsFirebaseJson.iteratorBegin,FirebaseJson.iteratorGet andFirebaseJson.iteratorEnd are used to parse all JSON object contents as a list which can be iterated with index.

FunctionFirebaseJson.clear is used to clear JSON object contents.

FunctionFirebaseJson.setFloatDigits is for float number precision when serialized to string.

FunctionFirebaseJson.setDoubleDigits is for double number precision when serialized to string.

FunctionFirebaseJsonArray.add is used for adding the new contents e.g. String, Number (int and double), Boolean, Array and Object to JSON array.

FunctionFirebaseJsonArray.set is for edit, overwrite, create new (if not exist) contents e.g. String, Number (int and double), Boolean, Array and Object at the defined relative path or defined index of JSON array.

FunctionFirebaseJsonArray.get works in the same way as FirebaseJson objects

FunctionFirebaseJsonArray.remove is used to remove the array's contents at the defined relative path or defined index of JSON array.

FunctionFirebaseJsonArray.toString is used for serializeing the JSON array object to writable objects e.g. char array, Arduino String, C/C++ string, WiFi/Ethernet Client and Hardware/Software Serial.

FunctionFirebaseJsonArray.serializedBufferLength is used for calculating the serialized buffer size that required for reserved buffer in serialization.

FunctionFirebaseJsonArray.responseCode is used to get the http code response header while read the WiFi/Ethernet Client usingFirebaseJson.toString.

FunctionFirebaseJsonArray.clear is used to clear JSON array object contents.

FunctionFirebaseJsonArray.setFloatDigits is for float number precision when serialized to string.

FunctionFirebaseJsonArray.setDoubleDigits is for double number precision when serialized to string.

The following example shows how to use FirebaseJson.

//Declare FirebaseJson object (global or local)FirebaseJson json;//Add name with value Living Room to JSON objectjson.add("name","Living Room");//Add temp1 with value 120 and temp1 with 40 to JSON object//Note: temp2 is not the child of temp1 as in previous version.json.add("temp1",120).add("temp2",40);//Add nested child contents directlyjson.set("unit/temp1","Farenheit");json.set("unit/temp2","Celcius");//Deserialize to serial with prettify optionjson.toString(Serial,true);Serial.println();Serial.println();/**This is the result of the above code{    "name": "Living Room",    "temp1": 120,    "temp2": 40,    "unit": {        "temp1": "Farenheit",        "temp2": "Celcius"    }}*///To set array to the above JSON using FirebaseJson directly//Set (add) array indexes 0,1,2,5,7 under temp1, the original value will be replaced with new one.json.set("temp1/[0]",47);json.set("temp1/[1]",28);json.set("temp1/[2]",34);json.set("temp1/[5]",23);//null will be created at array index 3,4 due to it's not yet assignedjson.set("temp1/[7]",25);//null will be created at array index 6//Print out as prettify stringjson.toString(Serial,true);Serial.println();Serial.println();/**The result of the above code{    "name": "Living Room",    "temp1": [        47,        28,        34,        null,        null,         23,        null,        25     ],    "temp2": 40,    "unit": {        "temp1": "Farenheit",        "temp2": "Celcius"    } }*///Try to remove temp1 array at index 1json.remove("temp1/[1]");//Try to remove temp2json.remove("temp2");//Print out as prettify stringjson.toString(Serial,true);Serial.println();Serial.println();/**The result of the above code{    "name": "Living Room",    "temp1": [         47,         34,         null,         null,         23,         null,         25    ],    "unit": {        "temp1": "Farenheit",        "temp2": "Celcius"    }}*///Now parse/read the contents from specific node unit/temp2//FirebaseJsonData is required to keep the parse results which can be accessed laterFirebaseJsonData result;json.get(result,"unit/temp2");if (result.success){//Print type of parsed data e.g string, int, double, bool, object, array, null and undefined  Serial.println(result.type);//Print its content e.g.string, int, double, bool whereas object, array and null also can access as string  Serial.println(result.to<String>());//Serial.println(result.to<int>());//Serial.println(result.to<bool>());//Serial.println(result.to<float>());//Serial.println(result.to<double>());}//The above code will show/**stringCelcius*///To get the array temp from FirebaseJsonjson.get(result,"temp1");//Prepare FirebaseJsonArray to take the array from FirebaseJsonFirebaseJsonArray arr;//Get array dataresult.get<FirebaseJsonArray>(arr);//Call get with FirebaseJsonData to parse the array at defined index ifor (size_t i =0; i < arr.size(); i++){//result now used as temporary object to get the parse results  arr.get(result, i);//Print its value  Serial.print("Array index:");  Serial.print(i);  Serial.print(", type:");  Serial.print(result.type);  Serial.print(", value:");  Serial.println(result.to<String>());}/**The result of above codeArray index: 0, type: int, value: 47Array index: 1, type: int, value: 34Array index: 2, type: null, value: nullArray index: 3, type: null, value: nullArray index: 4, type: int, value: 23Array index: 5, type: null, value: nullArray index: 6, type: int, value: 25*/

The following example shows how to use FirebaseJsonArray.

//Declare FirebaseJsonArray object (global or local)FirebaseJsonArray arr;//Add some dataarr.add("banana");arr.add("mango");arr.add("coconut");//Change the array contentsarr.set("[1]/food","salad");arr.set("[1]/sweet","cake");arr.set("[1]/appetizer","snack");arr.set("[2]","apple");// or arr.set(2, "apple");arr.set("[4]/[0]/[1]/amount",20);//Print out array as prettify stringarr.toString(Serial,true);Serial.println();Serial.println();/**This is the result of the above code[    "banana",    {        "food": "salad",        "sweet": "cake",        "appetizer": "snack"    },    "apple",    null,    [        [            null,            {                "amount": 20            }        ]    ]]*///Remove array content at /4/0/1/amountarr.remove("[4]/[0]/[1]/amount");//Print out as prettify stringarr.toString(Serial,true);Serial.println();Serial.println();/**The result of the above code[    "banana",    {        "food": "salad",        "sweet": "cake",        "appetizer": "snack"    },    "apple",    null,    [        [            null        ]    ]]*///Now parse/read the array contents at some indexFirebaseJsonData result;arr.get(result,"[1]/food");if(result.success){//Type of parsed data  Serial.println(result.type);//Its value  Serial.println(result.stringValue);//Serial.println(result.intValue);//Serial.println(result.boolValue);//Serial.println(result.floatValue);//Serial.println(result.doubleValue);}//The above code will show/**stringsalad*///To get the JSON object at array index 1 from FirebaseJsonArrayarr.get(result,"[1]");// or arr.get(result, 1);//Prepare FirebaseJson to take the JSON object from FirebaseJsonArrayFirebaseJson json;//Get FirebaseJson dataresult.get<FirebaseJson>(json);//Parse the JSON object as list//Get the number of itemssize_t len = json.iteratorBegin();FirebaseJson::IteratorValue value;for (size_t i =0; i < len; i++){    value = json.valueAt(i);    Serial.printf("%d, Type: %s, Name: %s, Value: %s\n", i, value.type == FirebaseJson::JSON_OBJECT ?"object" :"array", value.key.c_str(), value.value.c_str());}//Clear all list to free memoryjson.iteratorEnd();/**The result of the above code0, Type: object, Key: food, Value: salad1, Type: object, Key: sweet, Value: cake2, Type: object, Key: appetizer, Value: snack*/

All Available Functions

FirebaseJSON object Functions

Set or deserialize the JSON object data (JSON object literal) as FirebaseJson object.

paramdata The JSON object literal string to set or deserialize.

returnbool value represents the successful operation.

Call FirebaseJson.errorPosition to get the error.

boolsetJsonData(<string> data);

Clear internal buffer of FirebaseJson object.

returninstance of an object.

FirebaseJson &clear();

Set JSON data via derived Stream object to FirebaseJson object.

paramstream The pointer to or instance of derived Stream class.

returnboolean status of the operation.

boolreadFrom(Stream &stream);boolreadFrom(Stream *stream);

Set JSON data via derived Client object to FirebaseJson object.

paramclient The pointer to or instance of derived Client class.

returnboolean status of the operation.

boolreadFrom(Client &client);boolreadFrom(Client *client);

Set JSON data via Serial to FirebaseJson object.

paramser The Serial object.

paramser The timeout in millisecond to wait for Serial data to be completed.

returnboolean status of the operation.

boolreadFrom(<serial> &ser,uint32_t timeoutMS =5000) ;

Set JSON data via SdFat's SdFile object to FirebaseJson object.

paramsdFatFile The SdFat file object.

returnboolean status of the operation.

boolreadFrom(<SdFatFile> &sdFatFile);

Add null to FirebaseJson object.

paramkey The new key string that null to be added.

returninstance of an object.

FirebaseJson &add(<string> key);

Add value to FirebaseJson object.

paramkey The new key string that string value to be added.

paramvalue The value for the new specified key.

returninstance of an object.

The value that can be added is the following supported types e.g. flash string (PROGMEM and FPSTR), String, C/C++ std::string, const char*, char array, string literal, all integer and floating point numbers, boolean, FirebaseJson object and array.

FirebaseJson &add(<string> key, <type> value);

Get the FirebaseJson object serialized string.

paramout The writable object e.g. String, std::string, char array, Stream e.g ile, WiFi/Ethernet Client and LWMQTT, that accepts the returning string.

paramtopic The MQTT topic (LWMQTT).

paramprettify Boolean flag for return the pretty format string i.e. with text indentation and newline.

voidtoString(<type> out,bool prettify =false);voidtoString(<type> out, <string> topic,bool prettify =false);

Get the value from the specified node path in FirebaseJson object.

paramresult The reference of FirebaseJsonData that holds the result.

parampath Relative path to the specific node in FirebaseJson object.

paramprettify The text indentation and new line serialization option.

returnboolean status of the operation.

The FirebaseJsonData object holds the returned data which can be read from the following properties.

jsonData.stringValue - contains the returned string.

jsonData.intValue - contains the returned integer value.

jsonData.floatValue - contains the returned float value.

jsonData.doubleValue - contains the returned double value.

jsonData.boolValue - contains the returned boolean value.

jsonData.success - used to determine the result of the get operation.

jsonData.type - used to determine the type of returned value in string representsthe types of value e.g. string, int, double, boolean, array, object, null and undefined.

jsonData.typeNum used to determine the type of returned value is an integer as represented by the following value.

FirebaseJson::UNDEFINED = 0

FirebaseJson::OBJECT = 1

FirebaseJson::ARRAY = 2

FirebaseJson::STRING = 3

FirebaseJson::INT = 4

FirebaseJson::FLOAT = 5

FirebaseJson::DOUBLE = 6

FirebaseJson::BOOL = 7 and

FirebaseJson::NULL = 8

boolget(FirebaseJsonData &result, <string> path,bool prettify =false);

Parse and collect all node/array elements in FirebaseJson object.

returnnumber of child/array elements in FirebaseJson object.

size_titeratorBegin();

Get child/array elements from FirebaseJson objects at specified index.

paramindex The element index to get.

paramtype The integer which holds the type of data i.e. FirebaseJson::OBJECT and FirebaseJson::ARRAY

paramkey The string which holds the key/name of the object, can return empty String if the data type is an array.

paramvalue The string which holds the value for the element key or array.

voiditeratorGet(size_t index,int &type, String &key, String &value);

Get child/array elements from FirebaseJson objects at specified index.

paramindex The element index to get.

return IteratorValue struct

This should call after iteratorBegin.

The IteratorValue struct contains the following members:int typeString keyString value

IteratorValuevalueAt(size_t index);

Clear all iterator buffer (should be called since iteratorBegin was called).

voiditeratorEnd();

Set null to FirebaseJson object at the specified node path.

parampath The relative path that null to be set.

The relative path can be mixed with array index (number placed inside square brackets) and node names e.g. /myRoot/[2]/Sensor1/myData/[3].

voidset(<string> path);

Set value to FirebaseJson object at the specified node path.

parampath The relative path that string value to be set.

paramvalue The value to set.

The relative path can be mixed with array index (number placed inside square brackets) and node namese.g. /myRoot/[2]/Sensor1/myData/[3].

The value that can be added is the following supported types e.g. flash string (PROGMEM and FPSTR), String, C/C++ std::string, const char*, char array, string literal, all integer and floating point numbers, boolean, FirebaseJson object and array.

voidset(<string> path, <type> value);

Remove the specified node and its content.

parampath The relative path to remove its contents/children.

returnbool value represents the successful operation.

boolremove(<string> path);

Get the error position at the JSON object literal from parsing.

returnthe position of error in JSON object literal

Return -1 when for no parsing error.

interrorPosition();

Get the size of serialized JSON object buffer.

paramprettify The text indentation and new line serialization option.

returnsize in byte of buffer

size_tserializedBufferLength(bool prettify =false);

Set the precision for float to JSON object.

paramdigits The number of decimal places.

voidsetFloatDigits(uint8_t digits);

Set the precision for double to JSON object.

paramdigits The number of decimal places.

voidsetDoubleDigits(uint8_t digits);

Get http response code of reading JSON data from WiFi/Ethernet Client.

returnthe response code of reading JSON data from WiFi/Ethernet Client

intresponseCode();

FirebaseJsonArray object functions

Set or deserialize the JSON array data (JSON array literal) as FirebaseJsonArray object.

paramdata The JSON array literal string to set or deserialize.

returnbool value represents the successful operation.

Call FirebaseJsonArray.errorPosition to get the error.

boolsetJsonArrayData(<string> data);

Add null to FirebaseJsonArray object.

returninstance of an object.

FirebaseJsonArray &add();

Add value to FirebaseJsonArray object.

paramvalue The value to add.

returninstance of an object.

The value that can be added is the following supported types e.g. flash string (PROGMEM and FPSTR), String, C/C++ std::string, const char*, char array, string literal, all integer and floating point numbers, boolean, FirebaseJson object and array.

FirebaseJsonArray &add(<type> value);

Add multiple values to FirebaseJsonArray object.

paramv The value of any type to add.

paramn The consecutive values of any type to add.

returninstance of an object.

e.g. add("a","b",1,2)

FirebaseJsonArray &add(First v, Next... n);

Set JSON array data via derived Stream object to FirebaseJsonArray object.

paramstream The pointer to or instance of derived Stream class.

returnboolean status of the operation.

boolreadFrom(Stream &stream);boolreadFrom(Stream *stream);

Set JSON data array via derived Client object to FirebaseJsonArray object.

paramclient The pointer to or instance of derived Client class.

returnboolean status of the operation.

boolreadFrom(Client &client);boolreadFrom(Client *client);

Set JSON array data via Serial to FirebaseJsonArray object.

paramser The Serial object.

paramser The timeout in millisecond to wait for Serial data to be completed.

returnboolean status of the operation.

boolreadFrom(<serial> &ser,uint32_t timeoutMS =5000) ;

Set JSON array data via SdFat's SdFile object to FirebaseJsonArray object.

paramsdFatFile The SdFat file object.

returnboolean status of the operation.

boolreadFrom(<SdFatFile> &sdFatFile);

Get the array value at the specified index or path from the FirebaseJsonArray object.

paramresult The reference of FirebaseJsonData object that holds data at the specified index.

paramindex_or_path Index of data or relative path to data in FirebaseJsonArray object.

returnboolean status of the operation.

The relative path must begin with array index (number placed inside square brackets) followed byother array indexes or node names e.g. /[2]/myData would get the data from myData key inside the array indexes 2

boolget(FirebaseJsonData &result, <intor string> index_or_path);

Parse and collect all node/array elements in FirebaseJsonArray object.

returnnumber of child/array elements in FirebaseJsonArray object.

size_titeratorBegin();

Get child/array elements from FirebaseJsonArray objects at specified index.

paramindex The element index to get.

paramtype The integer which holds the type of data i.e. FirebaseJson::OBJECT and FirebaseJson::ARRAY

paramkey The string which holds the key/name of the object, can return empty String if the data type is an array.

paramvalue The string which holds the value for the element key or array.

voiditeratorGet(size_t index,int &type, String &key, String &value);

Get child/array elements from FirebaseJsonArray objects at specified index.

paramindex The element index to get.

return IteratorValue struct

This should call after iteratorBegin.

The IteratorValue struct contains the following members:int typeString keyString value

IteratorValuevalueAt(size_t index);

Clear all iterator buffer (should be called since iteratorBegin was called).

voiditeratorEnd();

Get the length of array in FirebaseJsonArray object.

returnlength of the array.

size_tsize();

Get the FirebaseJsonArray object serialized string.

paramout The writable object e.g. String, std::string, char array, Stream e.g ile, WiFi/Ethernet Client and LWMQTT, that accepts the returning string.

paramprettify Boolean flag for return the pretty format string i.e. with text indentation and newline.

voidtoString(<type> out,bool prettify =false);

Get raw JSON Array.

returnraw JSON Array string

constchar *raw();

Get the size of serialized JSON array buffer.

paramprettify The text indentation and new line serialization option.

returnsize in byte of buffer

size_tserializedBufferLength(bool prettify =false);

Clear all array in FirebaseJsonArray object.

returninstance of an object.

FirebaseJsonArray &clear();

Set null to FirebaseJsonArray object at at specified index or path.

paramindex_or_path The array index or path that null to be set.

voidset(<intor string> index_or_path);

Set String to FirebaseJsonArray object at the specified index.

paramindex_or_path The array index or path that value to be set.

paramvalue The value to set.

voidset(<intor string> index_or_path, <type> value);

Remove the array value at the specified index or path from the FirebaseJsonArray object.

paramindex_or_path The array index or relative path to array to be removed.

returnbool value represents the successful operation.

boolremove(<intor string> index_or_path);

Get raw JSON.

returnraw JSON string

constchar *raw();

Get the error position at the JSON array literal from parsing.

returnthe position of error in JSON array literal

Return -1 when for no parsing error.

interrorPosition();

Set the precision for float to JSON Array object.

paramdigits The number of decimal places.

voidsetFloatDigits(uint8_t digits);

Set the precision for double to JSON Array object.

paramdigits The number of decimal places.

voidsetDoubleDigits(uint8_t digits);

FirebaseJsonData object functions

Get array data as FirebaseJsonArray object from FirebaseJsonData object.

paramjsonArray The returning FirebaseJsonArray object.

returnbool status for successful operation.

This should call after pares or get functions.

boolgetArray(FirebaseJsonArray &jsonArray);

Get array data as FirebaseJsonArray object from FirebaseJsonData object.

paramsource The JSON array string.

paramjsonArray The returning FirebaseJsonArray object.

returnbool status for successful operation.

This should call after pares or get functions.

boolgetArray(<string> source, FirebaseJsonArray &jsonArray);

Get array data as FirebaseJson object from FirebaseJsonData object.

paramjsonArray The returning FirebaseJson object.

returnbool status for successful operation.

This should call after pares or get functions.

boolgetJSON(FirebaseJson &json);

Get JSON data as FirebaseJson object from string.

paramsource The JSON string.

paramjson The returning FirebaseJsonArray object.

returnbool status for successful operation.

This should call after pares or get functions.

boolgetJSON(<string> source, FirebaseJson &json);

Cast the FirebaseJsonData object to object or primitive type variable.

return theThe object or primitive type variable.

to<type>();e.g. to<String>(), to<int>(), to<bool>()

FirebaseJsonData object properties

stringValue The String value of parses data.

intValue The int value of parses data.

doubleValue The double value of parses data.

floatValue The float value of parses data.

boolVlue The bool value of parses data.

success used to determine the result of the deserialize operation.

type The type String of parses data e.g. string, int, double, boolean, array, object, null and undefined.

typeNum The type (number) of parses data in form of the followingjsonDataType value.

FirebaseJson::UNDEFINED = 0

FirebaseJson::OBJECT = 1

FirebaseJson::ARRAY = 2

FirebaseJson::STRING = 3

FirebaseJson::INT = 4

FirebaseJson::FLOAT = 5

FirebaseJson::DOUBLE = 6

FirebaseJson::BOOL = 7 and

FirebaseJson::NULL = 8

License

The MIT License (MIT)

Copyright (c) 2024 K. Suwatchai (Mobizt)

Copyright (c) 2009-2017 Dave Gamble and cJSON contributors

Permission is hereby granted, free of charge, to any person returning a copy ofthis software and associated documentation files (the "Software"), to deal inthe Software without restriction, including without limitation the rights touse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies ofthe Software, and to permit persons to whom the Software is furnished to do so,subject to the following conditions:

The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESSFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS ORCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHERIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

🗃 JSON parser and builder for ESP8266, ESP32, Teensy3.x and Teensy4.x, SAM, SAMD and STM32 (128 k flash or more)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp