How to use the jsons.loads function in jsons

To help you get started, we’ve selected a few jsons examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github V0RT3X4 / python-sdk / tests / api / test_vessel_entity.py View on Github external
def test_serialize(self):
        with open("tests/api/examples/vessel_entity1.json", "r") as f:
            serialized = f.read()
            deserialized = jsons.loads(serialized, VesselEntity)

            assert ve == deserialized
github V0RT3X4 / python-sdk / tests / mock_client.py View on Github external
def _read(example_file) -> List[Dict]:
    with open(f"tests/api/examples/{example_file}", "r") as f:
        return jsons.loads(f.read(), List)
github ramonhagenaars / jsons / test_jsons.py View on Github external
def test_exception_wrong_json(self):
        with self.assertRaises(DecodeError):
            jsons.loads('{this aint no JSON!')

        try:
            jsons.loads('{this aint no JSON!')
        except DecodeError as err:
            self.assertEqual(None, err.target)
            self.assertEqual('{this aint no JSON!', err.source)
github ramonhagenaars / jsons / test_jsons.py View on Github external
def test_loads(self):
        class A:
            def __init__(self):
                self.name = 'A'

        class B:
            def __init__(self, a: A):
                self.a = a
                self.name = 'B'

        s = json.dumps({'a': {'name': 'A'}, 'name': 'B'})
        loaded_dict = jsons.loads(s)
        self.assertEqual('B', loaded_dict['name'])
        self.assertEqual('A', loaded_dict['a']['name'])

        loaded_obj = jsons.loads(s, B)
        self.assertEqual('B', loaded_obj.name)
        self.assertEqual('A', loaded_obj.a.name)
github V0RT3X4 / python-sdk / tests / api / test_product_entity.py View on Github external
def test_serialize(self):
        with open("tests/api/examples/product_entity1.json", "r") as f:
            serialized = f.read()
            deserialized = jsons.loads(serialized, ProductEntity)

            expected = ProductEntity(
                id="6f11b0724c9a4e85ffa7f1445bc768f054af755a090118dcf99f14745c261653",
                layer="group",
                probability=0.9369364,
                label="Crude & Condensates",
                source="model",
            )

            assert expected == deserialized
github V0RT3X4 / python-sdk / tests / api / test_cargo_movement.py View on Github external
def test_serialize(self):
        with open("tests/api/examples/cargo_movements.json", "r") as f:
            serialized = f.read()
            deserialized = jsons.loads(serialized, List[CargoMovement])

            assert [self.cm] == deserialized