Exposed functions and symbols¶
- rapidjson.__author__¶
The authors of the module.
- rapidjson.__version__¶
The version of the module.
- rapidjson.__rapidjson_exact_version__¶
The exact version of the RapidJSON library, as determined by
git describe
.
datetime_mode related constants
- rapidjson.DM_NONE¶
This is the default datetime_mode: neither
date
nordatetime
nortime
instances are recognized bydumps()
andloads()
.
- rapidjson.DM_ISO8601¶
In this datetime_mode mode
dumps()
andloads()
handledate
,datetime
anddate
instances representing those values using the ISO 8601 format.
- rapidjson.DM_UNIX_TIME¶
This mode tells RapidJSON to serialize
date
,datetime
andtime
as numeric timestamps: for the formers it is exactly the result of theirtimestamp()
method, that is as the number of seconds passed sinceEPOCH
;date
instances are serialized as the correspondingdatetime
instance with all the time slots set to 0;time
instances are serialized as the number of seconds since midnight.Since this is obviously irreversible, this flag is usable only for
dumps()
: an error is raised when passed toloads()
.
- rapidjson.DM_ONLY_SECONDS¶
This is usable in combination with
DM_UNIX_TIME
so that an integer representation is used, ignoring microseconds.
- rapidjson.DM_IGNORE_TZ¶
This can be used combined with
DM_ISO8601
orDM_UNIX_TIME
, to ignore the value’s timezones.
- rapidjson.DM_NAIVE_IS_UTC¶
This can be used combined with
DM_ISO8601
orDM_UNIX_TIME
, to tell RapidJSON that the naïve values (that is, without an explicit timezone) are already in UTC timezone.
- rapidjson.DM_SHIFT_TO_UTC¶
This can be used combined with
DM_ISO8601
orDM_UNIX_TIME
, to always shift values the UTC timezone.
uuid_mode related constants
- rapidjson.UM_NONE¶
This is the default uuid_mode:
UUID
instances are not recognized bydumps()
andloads()
.
- rapidjson.UM_CANONICAL¶
In this uuid_mode,
loads()
recognizes string values containing thexxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
canonical representation asUUID
instances;dumps()
emits same kind of representation forUUID
instances as a string value.
- rapidjson.UM_HEX¶
In this uuid_mode
loads()
recognizes string values containing exactly 32 hex digits or thexxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
canonical representation asUUID
instances;dumps()
emits the 32 hex digits ofUUID
instances as a string value.
number_mode related constants
- rapidjson.NM_NONE¶
This is the default number_mode: numeric values can be as wide as the memory allows.
- rapidjson.NM_DECIMAL¶
In this number_mode
loads()
will return floating point values asDecimal
instances instead offloat
;dumps()
will serializeDecimal
instances like any otherfloat
number.
- rapidjson.NM_NAN¶
This enables non-numbers (i.e.
nan
,+inf
and-inf
) handling in both directions.
- rapidjson.NM_NATIVE¶
In this alternative number_mode numeric values must fit into the underlying C library limits, with a considerable speed benefit.
parse_mode related constants
- rapidjson.PM_NONE¶
This is the default parse_mode: with the exception of the NaN and Infinite recognition active by default, the parser is in strict mode.
- rapidjson.PM_COMMENTS¶
In this parse_mode, the parser allows and ignores one-line
// ...
and multi-line/* ... */
comments
- rapidjson.PM_TRAILING_COMMAS¶
In this parse_mode, the parser allows and ignores trailing commas at the end of arrays and objects.
bytes_mode related constants
- rapidjson.BM_NONE¶
This disables the default handling mode (
BM_UTF8
) ofbytes
instances: they won’t be treated in any special way and will raise aTypeError
exception when encountered. On the other hand, in this mode they can be managed by a default handler.
- rapidjson.BM_UTF8¶
This is the default setting for bytes_mode: any
bytes
instance will be assumed to be anUTF-8
encoded string, and decoded accordingly.
iterable_mode related constants
- rapidjson.IM_ANY_ITERABLE¶
This is the default setting for iterable_mode: any iterable will be dumped as a
JSON
array.
- rapidjson.IM_ONLY_LISTS¶
This disables the default handling mode (
IM_ANY_ITERABLE
) of iterable values (with the exception ofstr
ings andlist
s): they won’t be treated in any special way and will raise aTypeError
exception when encountered. On the other hand, in this mode they can be managed by a default handler.
mapping_mode related constants
- rapidjson.MM_ANY_MAPPING¶
This is the default setting for mapping_mode: any mapping will be dumped as a
JSON
object.
- rapidjson.MM_ONLY_DICTS¶
This disables the default handling mode (
MM_ANY_MAPPING
) of generic mapping values, they won’t be treated likedict
s and will raise aTypeError
exception when encountered. On the other hand, in this mode they can be managed by a default handler.
- rapidjson.MM_COERCE_KEYS_TO_STRINGS¶
Since
JSON
objects require that all keys must be of type string, when a mapping contains non-string keys, it will be processed by the default handler if available, otherwise aTypeError
exception is raised.Alternatively, you can use the this option to automatically render such keys as their
str()
representation.
- rapidjson.MM_SKIP_NON_STRING_KEYS¶
In this mode, dict keys that are not of a basic type (
str
,int
,float
,bool
,None
) will be skipped instead of raising aTypeError
.
- rapidjson.MM_SORT_KEYS¶
Alphabetically order dictionary keys.
Exceptions
- exception rapidjson.JSONDecodeError¶
A subclass of
ValueError
, raised when trying to parse an invalidJSON
, either byValidator
objects or byloads()
function.
- exception rapidjson.ValidationError¶
Exception raised by
Validator
objects, a subclass ofValueError
.Its args attribute is a tuple with three string values, respectively the schema keyword that generated the failure, its JSON pointer and a JSON pointer to the error location in the (invalid) document.
write_mode related constants
- rapidjson.WM_COMPACT¶
The default dump mode, without any extra whitespace.
- rapidjson.WM_PRETTY¶
This selects the RapidJSON
PrettyWriter
, to produce more readableJSON
: each array’s item and object’s key will be preceded by a newline, and nested structures will be indented.
- rapidjson.WM_SINGLE_LINE_ARRAY¶
This tells the
PrettyWriter
to emit arrays on a single line, instead of separating items with a newline.