Enumerations | |
| enum | SerializationFormat { Compact, Pretty, MessagePack } |
| Describes format of serialized Json object. More... | |
Functions | |
| template<typename TSource , typename TDest > | |
| bool | getValue (const TSource &source, TDest &dest) |
| Copies a Json data value to a variable, but only if it exists. More... | |
| template<typename TSource , typename TDest > | |
| bool | getValueChanged (const TSource &source, TDest &dest) |
| Copies a Json data value to a variable, but only if it exists and its value has changed. More... | |
| SerializationFormat | operator++ (SerializationFormat &fmt) |
| template<typename TSource > | |
| size_t | measure (const TSource &source, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| Compute the size of a serialized Json object for a specified format. More... | |
| template<typename TSource , typename TDestination > | |
| size_t | serialize (const TSource &source, TDestination &destination, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| Write a Json object in a specified format. More... | |
| template<typename TSource , typename TPrint > | |
| std::enable_if< std::is_base_of< Print, TPrint >::value, size_t >::type | serialize (const TSource &source, TPrint *destination, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| Write a Json object in a specified format. More... | |
| template<typename TSource > | |
| size_t | serialize (const TSource &source, char *buffer, size_t bufferSize, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| Write a Json object in a specified format. More... | |
| template<typename TSource > | |
| String | serialize (const TSource &source, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| Serialize a Json object in a specified format, returning it in a String object. More... | |
| template<typename TSource > | |
| bool | saveToFile (const TSource &source, const String &filename, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| Save a Json object to a file in a specified format. More... | |
| template<typename TInput > | |
| bool | deserializeInternal (JsonDocument &doc, TInput &input, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| template<typename TInput > | |
| bool | deserialize (JsonDocument &doc, TInput &input, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| Read a JsonDocument from formatted data. More... | |
| template<typename TInput > | |
| std::enable_if<!std::is_base_of< Stream, TInput >::value, bool >::type | deserialize (JsonDocument &doc, TInput *input, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| Read a JsonDocument from formatted data. More... | |
| template<typename TStream > | |
| std::enable_if< std::is_base_of< Stream, TStream >::value, bool >::type | deserialize (JsonDocument &doc, TStream *input, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| Read a JsonDocument from formatted data. More... | |
| template<typename TInput > | |
| bool | deserialize (JsonDocument &doc, TInput *input, size_t inputSize, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| Read a JsonDocument from formatted data. More... | |
| bool | loadFromFile (JsonDocument &doc, const String &filename, SerializationFormat format=JSON_FORMAT_DEFAULT) |
| Parses the contents of a serialized file into a JsonDocument object. More... | |
Enumeration Type Documentation
◆ SerializationFormat
Describes format of serialized Json object.
| Enumerator | |
|---|---|
| Compact | Compact JSON format. |
| Pretty | Prettified JSON format, with spaces and line breaks. |
| MessagePack | Message Pack (compact binary) format. |
Function Documentation
◆ deserialize() [1/4]
| bool Json::deserialize | ( | JsonDocument & | doc, |
| TInput & | input, | ||
| SerializationFormat | format = JSON_FORMAT_DEFAULT |
||
| ) |
Read a JsonDocument from formatted data.
- Parameters
-
doc Document to store the decoded file input Where to get data from (see notes) format Format of the data
- Return values
-
bool true on success, false on error
- Note
- Supported read-only input types:
Stream& String& const String& const FlashString& -
String&is always read-only. If you wish to deserialize content in-situ, use:Json:: deserialize(doc, str.begin(), str.length(), format)
Don't forget to keep str in scope until you're finished with doc.
◆ deserialize() [2/4]
| std::enable_if<!std::is_base_of<Stream, TInput>::value, bool>::type Json::deserialize | ( | JsonDocument & | doc, |
| TInput * | input, | ||
| SerializationFormat | format = JSON_FORMAT_DEFAULT |
||
| ) |
Read a JsonDocument from formatted data.
- Parameters
-
doc Document to store the decoded file input Where to get data from (see notes) format Format of the data
- Return values
-
bool true on success, false on error
- Note
- Supported writeable input types (content will be modified in-situ):
char*
-
Supported read-only input types:
const char* const __FlashStringHelper* const FlashString*
◆ deserialize() [3/4]
| std::enable_if<std::is_base_of<Stream, TStream>::value, bool>::type Json::deserialize | ( | JsonDocument & | doc, |
| TStream * | input, | ||
| SerializationFormat | format = JSON_FORMAT_DEFAULT |
||
| ) |
Read a JsonDocument from formatted data.
- Parameters
-
doc Document to store the decoded file input Where to get data from (see notes) format Format of the data
- Return values
-
bool true on success, false on error
- Note
- Supports stream pointers (Stream and inherited classses) This function can be safely used with null pointers
◆ deserialize() [4/4]
| bool Json::deserialize | ( | JsonDocument & | doc, |
| TInput * | input, | ||
| size_t | inputSize, | ||
| SerializationFormat | format = JSON_FORMAT_DEFAULT |
||
| ) |
Read a JsonDocument from formatted data.
- Parameters
-
doc Document to store the decoded file input Where to get data from (see notes) inputSize Maximum number of bytes to read from inputformat Format of the data
- Return values
-
bool true on success, false on error
- Note
- Supported writeable input types (content will be modified in-situ):
char*, size_t
-
Supported read-only input types:
const char*, size_t const __FlashStringHelper*, size_t
◆ deserializeInternal()
| bool Json::deserializeInternal | ( | JsonDocument & | doc, |
| TInput & | input, | ||
| SerializationFormat | format = JSON_FORMAT_DEFAULT |
||
| ) |
◆ getValue()
| bool Json::getValue | ( | const TSource & | source, |
| TDest & | dest | ||
| ) |
Copies a Json data value to a variable, but only if it exists.
- Parameters
-
source Typically provided from JsonObject[key], JsonDocument[key] or JsonVariant[key] call dest Variable to store value, unchanged if datais null
- Return values
-
bool true if value exists and was written to value
- Note
- Use to perform existence check before assignment, without requiring additional
containsKeycall or temporary variant. Example:JsonDocument doc; ... String value1; if(!Json::getValue(doc["key1"], value1)) { // Perform required action when value1 doesn't exist, such as initialising defaults }
Where a simple default is required, use the | operator. Examples:
String value1 = doc["key1"].as<const char*> | "default value"; int value2 = doc["key2] | -1;
◆ getValueChanged()
| bool Json::getValueChanged | ( | const TSource & | source, |
| TDest & | dest | ||
| ) |
Copies a Json data value to a variable, but only if it exists and its value has changed.
- Parameters
-
source Typically provided from JsonObject[key], JsonDocument[key] or JsonVariant[key] call dest Variable to store value, unchanged if datais null
- Return values
-
bool true if value exists and has changed, valueupdated
◆ loadFromFile()
|
inline |
Parses the contents of a serialized file into a JsonDocument object.
- Parameters
-
doc Document to store the decoded file filename Name of file to create, will always be overwritten format Format of the data to be parsed
- Return values
-
bool true on success, false if the file couldn't be read or there was a parsing error
◆ measure()
| size_t Json::measure | ( | const TSource & | source, |
| SerializationFormat | format = JSON_FORMAT_DEFAULT |
||
| ) |
Compute the size of a serialized Json object for a specified format.
- Parameters
-
source JsonDocument, JsonArray, JsonObject or JsonVariant format Serialization format
- Return values
-
size_t Number of bytes that would be written when the document is serialized
◆ operator++()
|
inline |
◆ saveToFile()
| bool Json::saveToFile | ( | const TSource & | source, |
| const String & | filename, | ||
| SerializationFormat | format = JSON_FORMAT_DEFAULT |
||
| ) |
Save a Json object to a file in a specified format.
- Parameters
-
source JsonDocument, JsonArray, JsonObject, JsonVariant filename Name of file to create, will always be overwritten format Serialization format to use when writing
- Return values
-
bool true on success, false if the write failed
◆ serialize() [1/4]
| size_t Json::serialize | ( | const TSource & | source, |
| TDestination & | destination, | ||
| SerializationFormat | format = JSON_FORMAT_DEFAULT |
||
| ) |
◆ serialize() [2/4]
| std::enable_if<std::is_base_of<Print, TPrint>::value, size_t>::type Json::serialize | ( | const TSource & | source, |
| TPrint * | destination, | ||
| SerializationFormat | format = JSON_FORMAT_DEFAULT |
||
| ) |
Write a Json object in a specified format.
- Parameters
-
source JsonDocument, JsonArray, JsonObject or JsonVariant destination Where to write output (Print*) format Serialization format to use when writing
- Return values
-
size_t The number of bytes written
- Note
- This variant provides support for stream pointers, with null check
◆ serialize() [3/4]
| size_t Json::serialize | ( | const TSource & | source, |
| char * | buffer, | ||
| size_t | bufferSize, | ||
| SerializationFormat | format = JSON_FORMAT_DEFAULT |
||
| ) |
Write a Json object in a specified format.
- Parameters
-
source JsonDocument, JsonArray, JsonObject or JsonVariant buffer Buffer for output data bufferSize Size of buffer format Serialization format to use when writing
- Return values
-
size_t The number of bytes written
◆ serialize() [4/4]
| String Json::serialize | ( | const TSource & | source, |
| SerializationFormat | format = JSON_FORMAT_DEFAULT |
||
| ) |
1.8.13