diff options
author | Kevin LaFlamme <kevin@lolatravel.com> | 2016-09-01 12:26:43 -0400 |
---|---|---|
committer | Kevin LaFlamme <kevin@lolatravel.com> | 2016-09-01 12:26:43 -0400 |
commit | da17e3529c4e41173519ea18ff3ee908761ef5d4 (patch) | |
tree | e987a357593f5184b45cd8482ba544b5a8d66978 /simplejson/tests | |
parent | 4b1dab370f8a32aaa3f9140c38645093d3287b82 (diff) | |
download | simplejson-da17e3529c4e41173519ea18ff3ee908761ef5d4.tar.gz |
Add support for preprocessed JSON strings (with optimizations) in encoder
In some situations, you may have a large python dictionary you need to JSONify but one of the values inside the dict is already a JSON string. This is common when pulling an object from a database, for example, where one of the fields is a JSON blob/string. Previously you would have to deserialize and then reserialize that string just to serialize the high level object, but obviously this is unnecessarily slow. This changes adds a method/type that can be used to wrap a str and tell the serializer to just pass it through instead.
Diffstat (limited to 'simplejson/tests')
-rw-r--r-- | simplejson/tests/test_raw_json.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/simplejson/tests/test_raw_json.py b/simplejson/tests/test_raw_json.py new file mode 100644 index 0000000..6fa6349 --- /dev/null +++ b/simplejson/tests/test_raw_json.py @@ -0,0 +1,30 @@ +import unittest +import simplejson as json + +dct1 = { + 'key1': 'value1' +} + +dct2 = { + 'key2': 'value2', + 'd1': dct1 +} + +dct3 = { + 'key2': 'value2', + 'd1': json.dumps(dct1) +} + +dct4 = { + 'key2': 'value2', + 'd1': json.RawJSON(json.dumps(dct1)) +} + + +class TestRawJson(unittest.TestCase): + + def test_normal_str(self): + self.assertNotEqual(json.dumps(dct2), json.dumps(dct3)) + + def test_raw_json_str(self): + self.assertEqual(json.dumps(dct2), json.dumps(dct4)) |