TSDuck  v3.33-3070
MPEG Transport Stream Toolkit
ts::json Namespace Reference

Namespace for JSON (JavaScript Object Notation) classes. More...

Classes

class  Array
 Implementation of a JSON array. More...
 
class  False
 Implementation of a JSON false literal. More...
 
class  Null
 Implementation of a JSON null literal. More...
 
class  Number
 Implementation of a JSON number. More...
 
class  Object
 Implementation of a JSON object. More...
 
class  OutputArgs
 Command line arguments for JSON reports (--json, --json-line, --json-udp). More...
 
class  RunningDocument
 Representation of a "running" JSON document which is displayed on the fly. More...
 
class  String
 Implementation of a JSON string. More...
 
class  True
 Implementation of a JSON true literal. More...
 
class  Value
 Abstract base class of a JSON value. More...
 

Typedefs

typedef SafePtr< Value, NullMutexValuePtr
 Safe pointer to a JSON value (not thread-safe).
 
typedef std::list< ValuePtrValuePtrList
 A list of safe pointers to JSON values.
 
typedef std::vector< ValuePtrValuePtrVector
 A vector of safe pointers to JSON values.
 

Enumerations

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

Functions

ValuePtr Bool (bool value)
 Create a boolean JSON value. More...
 
ValuePtr Factory (Type type, const UString &value=UString())
 Create a JSON value by type. More...
 
bool IsInlineJSON (const UString &name)
 Check if a "file name" is in fact inline JSON content instead of a file name. More...
 
bool LoadFile (ValuePtr &value, const UString &filename, Report &report=(*(static_cast< ts::Report * >(ts::NullReport::Instance()))))
 Load a JSON value (typically an object or array) from a text file. More...
 
bool LoadStream (ValuePtr &value, std::istream &strm, Report &report=(*(static_cast< ts::Report * >(ts::NullReport::Instance()))))
 Load a JSON value (typically an object or array) from an open text stream. More...
 
bool Parse (ValuePtr &value, const UString &text, Report &report=(*(static_cast< ts::Report * >(ts::NullReport::Instance()))))
 Parse a JSON value (typically an object or array). More...
 
bool Parse (ValuePtr &value, const UStringList &lines, Report &report=(*(static_cast< ts::Report * >(ts::NullReport::Instance()))))
 Parse a JSON value (typically an object or array). More...
 
bool Parse (ValuePtr &value, TextParser &parser, bool jsonOnly, Report &report=(*(static_cast< ts::Report * >(ts::NullReport::Instance()))))
 Parse a JSON value (typically an object or array). More...
 

Variables

Null NullValue
 A general-purpose null JSON value. More...
 
const Enumeration TypeEnum
 Enumeration description of ts::json::Type.
 

Detailed Description

Namespace for JSON (JavaScript Object Notation) classes.

Enumeration Type Documentation

◆ Type

enum 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

◆ 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 = (*(static_cast< ts::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 = (*(static_cast< ts::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 = (*(static_cast< ts::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 = (*(static_cast< ts::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 = (*(static_cast< ts::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.

Variable Documentation

◆ NullValue

Null ts::json::NullValue
extern

A general-purpose null JSON value.

This object is not marked as "const" but, like any Null value, all modificaton operations do nothing.