Wp.SpaJsonParser

Fields

None

Methods

class

new_array (json)

class

new_object (json)

class

new_undefined (json)

end ()

get_boolean ()

get_float ()

get_int ()

get_json ()

get_null ()

get_string ()

ref ()

unref ()

Details

class Wp.SpaJsonParser

New in version 0.4.8.

classmethod new_array(json)
Parameters:

json (Wp.SpaJson) – the spa json array to parse

Returns:

The new spa json parser

Return type:

Wp.SpaJsonParser

Creates a spa json array parser. The json object must be valid for the entire life-cycle of the returned parser.

classmethod new_object(json)
Parameters:

json (Wp.SpaJson) – the spa json object to parse

Returns:

The new spa json parser

Return type:

Wp.SpaJsonParser

Creates a spa json object parser. The json object must be valid for the entire life-cycle of the returned parser.

classmethod new_undefined(json)
Parameters:

json (Wp.SpaJson) – the spa json to parse

Returns:

The new spa json parser

Return type:

Wp.SpaJsonParser

Creates a new spa json parser for undefined type of data. The json object must be valid for the entire life-cycle of the returned parser.

This function allows creating a parser object for any type of spa json and is mostly useful to parse non-standard JSON data that should be treated as if it were an object or array, but does not start with a ‘{’ or ‘[’ character. Such data can be for instance a comma-separated list of single values (array) or key-value pairs (object). Such data is also the main configuration file, which is an object but doesn’t start with a ‘{’ character. If the data is an array or object, the parser will not enter it and the only token it will be able to parse is the same json object that is passed in as an argument. Use Wp.SpaJsonParser.new_array() or Wp.SpaJsonParser.new_object() to parse arrays or objects.

New in version 0.5.0.

end()
get_boolean()
Returns:

True if the value was obtained, False otherwise

value:

the boolean value

Return type:

(bool, value: bool)

Gets the boolean value from a spa json parser.

get_float()
Returns:

True if the value was obtained, False otherwise

value:

the float value

Return type:

(bool, value: float)

Gets the float value from a spa json parser object.

get_int()
Returns:

True if the value was obtained, False otherwise

value:

the int value

Return type:

(bool, value: int)

Gets the int value from a spa json parser object.

get_json()
Returns:

The spa json value or None if it could not be obtained

Return type:

Wp.SpaJson

Gets the spa json value from a spa json parser object.

the returned spa json object references the original data instead of copying it, therefore the original data must be valid for the entire life-cycle of the returned object

get_null()
Returns:

True if the null value is present, False otherwise

Return type:

bool

Gets the null value from a spa json parser.

get_string()
Returns:

The newly allocated parsed string

Return type:

str

Gets the string value from a spa json parser object.

ref()
Returns:

self with an additional reference count on it

Return type:

Wp.SpaJsonParser

Increases the reference count of a spa json parser.

unref()

Decreases the reference count on self and frees it when the ref count reaches zero.