TSDuck v3.40-4163
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches

Representation of JSON documents. More...

Collaboration diagram for JSON:

Classes

class  ts::json::Array
 Implementation of a JSON array. More...
 
class  ts::json::False
 Implementation of a JSON false literal. More...
 
class  ts::json::Null
 Implementation of a JSON null literal. More...
 
class  ts::json::Number
 Implementation of a JSON number. More...
 
class  ts::json::Object
 Implementation of a JSON object. More...
 
class  ts::json::RunningDocument
 Representation of a "running" JSON document which is displayed on the fly. More...
 
class  ts::json::String
 Implementation of a JSON string. More...
 
class  ts::json::True
 Implementation of a JSON true literal. More...
 
class  ts::json::Value
 Abstract base class of a JSON value. More...
 

Typedefs

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.
 

Enumerations

enum class  ts::json::Type {
  ts::json::Type::Null ,
  ts::json::Type::True ,
  ts::json::Type::False ,
  ts::json::Type::String ,
  ts::json::Type::Number ,
  ts::json::Type::Object ,
  ts::json::Type::Array
}
 Definition of the type of a value. More...
 

Functions

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 Namests::json::TypeEnum ()
 Enumeration description of ts::json::Type.
 

Detailed Description

Representation of JSON documents.

Enumeration Type Documentation

◆ Type

enum class ts::json::Type
strong

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.

Function Documentation

◆ TypeEnum()

const Names & ts::json::TypeEnum ( )

Enumeration description of ts::json::Type.

Returns
A constant reference to the enumeration description.

◆ Factory()

ValuePtr ts::json::Factory ( Type  type,
const UString value = UString() 
)

Create a JSON value by type.

Parameters
[in]typeThe type JSON object to create.
[in]valueOptional 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()

ValuePtr ts::json::Bool ( bool  value)

Create a boolean JSON value.

Parameters
[in]valueA boolean value.
Returns
A smart pointer to the created JSON value, either a True or False literal.

◆ Parse() [1/3]

bool ts::json::Parse ( ValuePtr value,
const UStringList lines,
Report report = (ts::NullReport::Instance()) 
)

Parse a JSON value (typically an object or array).

Parameters
[out]valueA smart pointer to the parsed JSON value (null on error).
[in]linesList of text lines forming the JSON value.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ Parse() [2/3]

bool ts::json::Parse ( ValuePtr value,
const UString text,
Report report = (ts::NullReport::Instance()) 
)

Parse a JSON value (typically an object or array).

Parameters
[out]valueA smart pointer to the parsed JSON value (null on error).
[in]textThe text forming the JSON value.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ Parse() [3/3]

bool ts::json::Parse ( ValuePtr value,
TextParser parser,
bool  jsonOnly,
Report report = (ts::NullReport::Instance()) 
)

Parse a JSON value (typically an object or array).

Parameters
[out]valueA smart pointer to the parsed JSON value (null on error).
[in,out]parserA text parser.
[in]jsonOnlyIf 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]reportWhere to report errors.
Returns
True on success, false on error.

◆ LoadFile()

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.

Parameters
[out]valueA smart pointer to the parsed JSON value (null on error).
[in]filenameThe 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]reportWhere to report errors.
Returns
True on success, false on error.

◆ LoadStream()

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.

Parameters
[out]valueA smart pointer to the parsed JSON value (null on error).
[in,out]strmA standard text stream in input mode.
[in,out]reportWhere 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]nameA file name string.
Returns
True if name contains inline JSON content, false otherwise.