Representation of JSON documents.
More...
|
using | ts::json::ValuePtr = std::shared_ptr< Value > |
| Safe pointer to a JSON value (not thread-safe).
|
|
using | ts::json::ValuePtrList = std::list< ValuePtr > |
| A list of safe pointers to JSON values.
|
|
using | ts::json::ValuePtrVector = std::vector< ValuePtr > |
| A vector of safe pointers to JSON values.
|
|
|
ValuePtr | ts::json::Bool (bool value) |
| Create a boolean JSON value.
|
|
ValuePtr | ts::json::Factory (Type type, const UString &value=UString()) |
| Create a JSON value by type.
|
|
bool | ts::json::IsInlineJSON (const UString &name) |
| Check if a "file name" is in fact inline JSON content instead of a file name.
|
|
bool | ts::json::LoadFile (ValuePtr &value, const UString &filename, Report &report=(ts::NullReport::Instance())) |
| Load a JSON value (typically an object or array) from a text file.
|
|
bool | ts::json::LoadStream (ValuePtr &value, std::istream &strm, Report &report=(ts::NullReport::Instance())) |
| Load a JSON value (typically an object or array) from an open text stream.
|
|
bool | ts::json::Parse (ValuePtr &value, const UString &text, Report &report=(ts::NullReport::Instance())) |
| Parse a JSON value (typically an object or array).
|
|
bool | ts::json::Parse (ValuePtr &value, const UStringList &lines, Report &report=(ts::NullReport::Instance())) |
| Parse a JSON value (typically an object or array).
|
|
bool | ts::json::Parse (ValuePtr &value, TextParser &parser, bool jsonOnly, Report &report=(ts::NullReport::Instance())) |
| Parse a JSON value (typically an object or array).
|
|
const Names & | ts::json::TypeEnum () |
| Enumeration description of ts::json::Type.
|
|
Representation of JSON documents.
◆ Type
Definition of the type of a value.
JSON defines 7 types of value.
Enumerator |
---|
Null | Null literal.
|
True | True literal.
|
False | False literal.
|
String | String value.
|
Number | Number value (integer only for now).
|
Object | Structured object.
|
Array | Array of values.
|
◆ TypeEnum()
const Names & ts::json::TypeEnum |
( |
| ) |
|
Enumeration description of ts::json::Type.
- Returns
- A constant reference to the enumeration description.
◆ Factory()
Create a JSON value by type.
- Parameters
-
[in] | type | The type JSON object to create. |
[in] | value | Optional value. For TypeString, use this value. For TypeNumber, convert the string into a number (zero on error). For all other types, the value is ignored. |
- Returns
- A smart pointer to the created JSON value.
◆ Bool()
Create a boolean JSON value.
- Parameters
-
[in] | value | A boolean value. |
- Returns
- A smart pointer to the created JSON value, either a True or False literal.
◆ Parse() [1/3]
Parse a JSON value (typically an object or array).
- Parameters
-
[out] | value | A smart pointer to the parsed JSON value (null on error). |
[in] | lines | List of text lines forming the JSON value. |
[in,out] | report | Where to report errors. |
- Returns
- True on success, false on error.
◆ Parse() [2/3]
Parse a JSON value (typically an object or array).
- Parameters
-
[out] | value | A smart pointer to the parsed JSON value (null on error). |
[in] | text | The text forming the JSON value. |
[in,out] | report | Where to report errors. |
- Returns
- True on success, false on error.
◆ Parse() [3/3]
Parse a JSON value (typically an object or array).
- Parameters
-
[out] | value | A smart pointer to the parsed JSON value (null on error). |
[in,out] | parser | A text parser. |
[in] | jsonOnly | If true, the parsed text shall not contain anything else than the JSON value (except white spaces). If false, on output, the position of the parser is right after the JSON value. |
[in,out] | report | Where to report errors. |
- Returns
- True on success, false on error.
◆ LoadFile()
Load a JSON value (typically an object or array) from a text file.
- Parameters
-
[out] | value | A smart pointer to the parsed JSON value (null on error). |
[in] | filename | The name of the JSON file. If empty or "-", the standard input is used. If filename starts with "{" or "[", this is considered as "inline JSON content". The document is loaded from this string instead of reading a file. |
[in,out] | report | Where to report errors. |
- Returns
- True on success, false on error.
◆ LoadStream()
Load a JSON value (typically an object or array) from an open text stream.
- Parameters
-
[out] | value | A smart pointer to the parsed JSON value (null on error). |
[in,out] | strm | A standard text stream in input mode. |
[in,out] | report | Where to report errors. |
- Returns
- True on success, false on error.
◆ IsInlineJSON()
bool ts::json::IsInlineJSON |
( |
const UString & |
name | ) |
|
Check if a "file name" is in fact inline JSON content instead of a file name.
We currently only test if the name starts with '{' or '['. This will fail if we port TSDuck to OpenVMS, however...
- Parameters
-
[in] | name | A file name string. |
- Returns
- True if name contains inline JSON content, false otherwise.