Hello Rhino community,
When i try to export, through the below python script, the format isn’t as wished… i linked to JSON formats, the one which i get when export, and the one i want. i simply created the wanted JSON format by copying the data from the panel and pasted into the file. This is also why i don’t really get why it comes out in a way other format?
Anybody encoutnered this before?
import rhinoscriptsyntax as rs
import json
# Export 'x' as a JSON file if 'run' is true and let the user choose the path
if run:
default_filename = "Element.json"
default_directory = rs.DocumentPath()
save_path = rs.SaveFileName("Save JSON file", "JSON Files (*.json)|*.json||", default_directory, default_filename)
if save_path:
try:
# Convert the entire list 'x' to a JSON string
json_string = json.dumps(x, indent=1, ensure_ascii=False)
# Manually encode the JSON string as UTF-8
encoded_json_string = json_string.encode('utf-8')
# Write the encoded data to the file
with open(save_path, 'wb') as outfile:
outfile.write(encoded_json_string)
print("JSON file saved successfully.")
except Exception as e:
print("Error saving JSON file:", e)
Element_from Grasshopper export.json (1.4 KB)
Element_wanted form.json (1.3 KB)
Grasshopper_Json Extract 2.0.gh (28.9 KB)
Construction.json (157.7 KB)
Element.json (38.0 KB)