-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathminijson.py
More file actions
26 lines (21 loc) · 970 Bytes
/
minijson.py
File metadata and controls
26 lines (21 loc) · 970 Bytes
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
'''
Provides a standard data format with unique representations of data. That
is, each set of data has exactly one representation. To that effect, we
render the data is minified json and encode it as utf-8.
'''
import unittest
import json
def encode(data):
return json.dumps(data, encoding='utf-8', separators = (',', ':'), sort_keys=True)
def decode(minijson):
return json.loads(minijson)
class TestMiniJson(unittest.TestCase):
def testAll(self):
for reference, data in [
(r'''{}''', {}),
(r'''{"objtype":"card","text":"title\n\n\"body\" text","x":34}''', {'objtype':'card', 'x': 34, "text":'''title\n\n"body" text'''}),
(r'''{"cards":["abcd","de43"],"objtype":"manifest","parent":"abcdef123456"}''', {'objtype': 'manifest', 'parent': 'abcdef123456', 'cards': ['abcd', 'de43']}),
]:
self.assertEqual(encode(data), reference.encode('utf-8'))
if __name__ == '__main__':
unittest.main()