RawJSON class

class rapidjson.RawJSON(value)

Preserialized JSON string.


value (str) – the string that rapidjson should use verbatim when serializing this object

Some applications might decide to store JSON-serialized objects in their database, but might need to assemble them in a bigger JSON.

The RawJSON class serves this purpose. When serialized, the string value provided will be used verbatim, whitespace included:

>>> raw_list = RawJSON('[1, 2,3]')
>>> dumps({'foo': raw_list})
'{"foo":[1, 2,3]}'


python-rapidjson runs no checks on the preserialized data. This means that it can potentially output invalid JSON, if you provide it:

>>> raw_list = RawJSON('[1, ')
>>> dumps({'foo': raw_list})
'{"foo":[1, }'