def test_to_json_empty_array(self): self.assertEqual(string_functions.to_json({"foo": []}), '{"foo": []}')
def test_to_json_basic_array(self): self.assertEqual(string_functions.to_json({"foo": [1, 2, "three"]}), '{"foo": [1, 2, "three"]}')
def test_to_basic_object(self): self.assertEqual(string_functions.to_json({"foo": "bar"}), '{"foo": "bar"}')
def test_to_json_basic_number(self): self.assertEqual(string_functions.to_json({"foo": 1}), '{"foo": 1}')
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_to_basic_object(self): assert string_functions.to_json({"foo": "bar"}) == '{"foo": "bar"}'
def test_to_json_false(self): assert string_functions.to_json({"foo": False}) == '{"foo": false}'
def test_to_json_false(self): self.assertEqual(string_functions.to_json({"foo": False}), '{"foo": false}')
def test_to_json_nested_object(self): assert string_functions.to_json({"foo": { "bar": 2 }}) == '{"foo": {"bar": 2}}'
def test_to_json_true(self): assert string_functions.to_json({"foo": True}) == '{"foo": true}'
def test_to_json_basic_array(self): assert string_functions.to_json({"foo": [1, 2, 1.75, "three"] }) == '{"foo": [1, 2, 1.75, "three"]}'
def test_to_json_empty_array(self): assert string_functions.to_json({"foo": []}) == '{"foo": []}'
def test_to_json_basic_number(self): assert string_functions.to_json({"foo": 1}) == '{"foo": 1}'
def test_to_json_nested_object(self): self.assertEqual(string_functions.to_json({"foo": {"bar": 2}}), '{"foo": {"bar": 2}}')
def test_to_json_null(self): assert string_functions.to_json({"foo": None}) == '{"foo": null}'
def test_to_json_true(self): self.assertEqual(string_functions.to_json({"foo": True}), '{"foo": true}')
def to_file(filename, obj): string = to_json(obj) with open(filename, 'w') as f: f.write(string) f.close()
def test_to_json_null(self): self.assertEqual(string_functions.to_json({"foo": None}), '{"foo": null}')
def test_to_json_empty_object(self): self.assertEqual(string_functions.to_json({}), '{}')
def build(self) -> JSONObject: jo = JSONObject() import string_functions jo.json = string_functions.to_json(self.fields) return jo
def test_to_json_empty_object(self): assert string_functions.to_json({}) == '{}'