def test_from_json_empty_array(self):
     self.assertEqual(string_functions.from_json('{"foo":[]}'), {"foo": []})
 def test_from_json_basic_array(self):
     self.assertEqual(string_functions.from_json('{"foo":[1,2,"three"]}'), {"foo": [1, 2, "three"]})
 def test_from_basic_object(self):
     self.assertEqual(string_functions.from_json('{"foo":"bar"}'), {"foo": "bar"})
 def test_from_json_basic_number(self):
     self.assertEqual(string_functions.from_json('{"foo":1}'), {"foo": 1})
 def test_from_json_basic_whitespace(self):
     self.assertEqual(string_functions.from_json('{ "foo" : [1, 2, "three", 4] }'), {"foo": [1, 2, "three", 4]})
 def test_from_json_empty_array(self):
     assert string_functions.from_json('{"foo":[]}') == {"foo": []}
 def test_from_json_basic_whitespace(self):
     assert string_functions.from_json(
         '{ "foo" : [1, 2, "three", 4] }') == {
             "foo": [1, 2, "three", 4]
         }
 def test_from_json_false(self):
     self.assertEqual(string_functions.from_json('{"foo":false}'), {"foo": False})
 def test_from_json_false(self):
     assert string_functions.from_json('{"foo":false}') == {"foo": False}
 def test_from_json_null(self):
     assert string_functions.from_json('{"foo":null}') == {"foo": None}
 def test_from_json_true(self):
     assert string_functions.from_json('{"foo":true}') == {"foo": True}
 def test_from_json_nested_object(self):
     assert string_functions.from_json('{"foo":{"bar":2}}') == {
         "foo": {
             "bar": 2
         }
     }
 def test_from_json_basic_array(self):
     assert string_functions.from_json('{"foo":[-1.75,1,2,"three"]}') == {
         "foo": [-1.75, 1, 2, "three"]
     }
 def test_from_json_nested_object(self):
     self.assertEqual(string_functions.from_json('{"foo":{"bar":2}}'), {"foo": {"bar": 2}})
 def test_from_json_empty_object(self):
     assert string_functions.from_json('{}') == {}
 def test_from_json_true(self):
     self.assertEqual(string_functions.from_json('{"foo":true}'), {"foo": True})
 def test_from_basic_object(self):
     assert string_functions.from_json('{"foo":"bar"}') == {"foo": "bar"}
 def test_from_json_null(self):
     self.assertEqual(string_functions.from_json('{"foo":null}'), {"foo": None})
 def test_from_json_empty_object(self):
     self.assertEqual(string_functions.from_json('{}'), {})
예제 #20
0
import logging

from json_builder import JSONObjectBuilder, JSONObject
from string_functions import to_json, from_json

if __name__ == '__main__':
    logging.basicConfig(
        format='%(asctime)s %(levelname)s [%(name)s] %(message)s',
        level=logging.INFO)

    to_json([{"foo": [1, 2, '2']}])
    from_json('{ "foo" : [1, 2, 3, 4] }')

    jo = JSONObject.builder().put_string("JSON1", "Hello World!"). \
        put_string("JSON2", "Hello my World!"). \
        put_string(1, JSONObjectBuilder().put_list("key1", "value1")).\
        put_list("list", [1, 2, True]).\
        put_object('obj', {'k1': 2, 'k2': 3}).\
        put_list('list2', ['1\"']).\
        put_object('obj', JSONObjectBuilder().put_list("key1", []).build()). \
        put_list('list3', [1, JSONObjectBuilder().put_list("key1", []).build()]).\
        put_string('1\\n\\', '1\t2').\
        build()

    print(jo.json)

    from_json([])
 def test_from_json_basic_number(self):
     assert string_functions.from_json('{"foo":1}') == {"foo": 1}