Godot Version
4.4.1.stable
Question
I’m having trouble storing vectors in JSON format and parsing it back into the vector data type. I’m wondering if there is no concrete way to do this? If there isn’t I plan to just have each value stored in the JSON be an array like so: [value, integer from typeof()]. Where I just use the second value to convert the type back. However this isn’t optimal. Is there anyway to make this easier or if I’m doing something wrong with JSON?
Here’s some snippets of code from mine:
# store values one at a time in dictionary
child_tree_data.set("global_position", child.global_position)
# take the final collective dictionary and convert it to JSON (and store it in a file)
JSON.stringify(tree_data)
# parse the JSON file to a dictionary and plug it in to my function which sets each value
var save_data = JSON.parse_string(file.get_as_text())
print(apply_tree_data(current_level, save_data))
# here I set the node property to the value
# for simple values that JSON supports like floats it works: 0.0
# vectors however continue to remain strings: "(0.0, 0.0, 0.0)"
node.set(key, value)
I did some googling when I encountered this issue and it seems JSON doesn’t support vectors, and when storing it JSON.stringify() just converts it to a string, but JSON.parse_string() doesn’t convert it back (which feels a little dumb?). Anyway to do this easily other than the method I mentioned at the top.