MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / serialize_result

Function serialize_result

src/ifcedit/ifcedit/run.py:125–137  ·  view source on GitHub ↗

Serialize an API result to a JSON-friendly structure.

(value)

Source from the content-addressed store, hash-verified

123
124
125def serialize_result(value) -> object:
126 """Serialize an API result to a JSON-friendly structure."""
127 if value is None:
128 return None
129 if isinstance(value, ifcopenshell.entity_instance):
130 return _serialize_entity(value)
131 if isinstance(value, (list, tuple, set, frozenset)):
132 return [serialize_result(item) for item in value]
133 if isinstance(value, dict):
134 return {str(k): serialize_result(v) for k, v in value.items()}
135 if isinstance(value, (str, int, float, bool)):
136 return value
137 return str(value)
138
139
140def _serialize_entity(entity: ifcopenshell.entity_instance) -> dict:

Callers 7

test_noneMethod · 0.90
test_stringMethod · 0.90
test_intMethod · 0.90
test_entityMethod · 0.90
test_listMethod · 0.90
test_dictMethod · 0.90
run_apiFunction · 0.85

Calls 2

_serialize_entityFunction · 0.85
itemsMethod · 0.45

Tested by 6

test_noneMethod · 0.72
test_stringMethod · 0.72
test_intMethod · 0.72
test_entityMethod · 0.72
test_listMethod · 0.72
test_dictMethod · 0.72