.. currentmodule:: rapidjson
.. testsetup:: from rapidjson import RawJSON, dumps
Preserialized JSON string.
| param str value: | the string that rapidjson should use verbatim when serializing this
object (except non-ASCII escaping when ensure_ascii=True) |
|---|
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
retain its spelling and whitespace. With ensure_ascii=True (the default), non-ASCII
characters are emitted as JSON Unicode escapes; ensure_ascii=False preserves them:
>>> raw_list = RawJSON('[1, 2,3]')
>>> dumps({'foo': raw_list})
'{"foo":[1, 2,3]}'Warning
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, }'