hello, i cant seem to load json files, i keep getting the error invalid set index 'position' with value of type 'string'

i have the vector stored in --data.Fnum[0].pt1.pos--, save it to json from the original --root1.Fnum[0].pt1.pos-- they both print (-4, 41) although i think one is a string iam not sure... ?

is there a way parse json files as values ?

func _loadAnim():
	
	if ( loadFileName != "" ):
		
		var file = File.new();
		file.open(loadFileName, File.READ);
		var data = parse_json(file.get_as_text());
		file.close()
		
		
		#print(data.Fnum[0] )
		#print(root1.Fnum[0] )
		
		if typeof(data.Fnum[0].pt1.pos) == TYPE_STRING:
			print("is string");
		else:
			print("jkfdhgjkfdhgjkfdhjkgh")
		
		animFrameMax = data.Fnum.size();
		
		#root1 = data;
		
		isLoading = false;

#log: is string

it seems using json is not recomended all vectors need to be converted from "strings" to var File.store_var() works better

save:

	var path="res://anims/" + saveFileName; 
	
	var file = File.new()
	file.open(path, File.WRITE)
	file.store_var(root1);
	file.close()

load:

func _loadAnim():
	
	if ( loadFileName != "" ):
		
		
		var file = File.new()
		file.open(loadFileName, File.READ)
		root1 = file.get_var()
		file.close()
		
		
		
		animFrameMax = root1.Fnum.size();
		
		#root1 = data;
		
		isLoading = false;

.

    func _on_FileDialog_file_selected(path: String) -> void:
    	
    	loadFileName = path; #--'res://anims/test2.anim'
    	_loadAnim();
7 months later

Using the *_float functions twice instead of *_var makes the file smaller by 8 bytes per vector, because the type of the value doesen't need to be stored.

func get_vector2(file : File) -> Vector2:
    return Vector2(file.get_float(), file.get_float())

func store_vector2(file : File, vector : Vector2) -> void:
    file.store_float(vector.x)
    file.store_float(vector.y)
a month later