File: rawjson.rst

package info (click to toggle)
python-rapidjson 1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,368 kB
  • sloc: cpp: 3,332; python: 1,990; makefile: 106
file content (45 lines) | stat: -rw-r--r-- 1,202 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
.. -*- coding: utf-8 -*-
.. :Project:   python-rapidjson -- RawJSON class documentation
.. :Author:    Silvio Tomatis <silviot@gmail.com>
.. :License:   MIT License
.. :Copyright: © 2018 Silvio Tomatis
.. :Copyright: © 2018, 2020 Lele Gaifax
..

===============
 RawJSON class
===============

.. currentmodule:: rapidjson

.. testsetup::

   from rapidjson import RawJSON, dumps

.. class:: RawJSON(value)

   Preserialized JSON string.

   :param str value: 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:

.. doctest::

    >>> 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:

   .. doctest::

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