ifcopenshell validate How to output legal json
when using json_logger with this sample script
outfile = open(target_file, "wb") # /path/file.ifc
json_logger = ifcopenshell.validate.json_logger()
ifcopenshell.validate.validate(ifc_file, json_logger)
original_stdout = sys.stdout # Save a reference to the original standard output
print(f"original_stdout\n{original_stdout}")
with open(target_file, 'w') as outfile:
sys.stdout = outfile # Change the standard output to the file we created.
print(json_logger.statements)
sys.stdout = original_stdout # Reset the standard output to its original value
outfile.close()
print(json_logger.statements)
Output from json_logger.statements is single line / single quoted
[{'level': 'error', 'message': 'Attribute <entity IfcFurnitureType>.<attribute AssemblyPlace: <enumeration IfcAssemblyPlaceEnum: (FACTORY, NOTDEFINED, SITE)>> not optional', 'instance': #12552 .........................
so question is HowTo get output as valid json file?
Comments
Does anyone know if there's a way to serialize full ifcopenshell entities?
@CadGiru what do you want a json for? if you don't need to reconstruct the objects, but just want to store the info in a file, you could just store the string representation of the entities:
@cvillagrasa Corect, however I need to reconstruct the objects for further processing...