Error: trying to assign value of type nil to variable of type dictionary

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Castor1010

Hello everyone
im following this tutorial: https://www.youtube.com/watch?v=g1x8ct2Slok&t=159s
and i keep getting the error: trying to assign value of type nil to variable of type dictionary

this is my code:
extends Node

var item_data: Dictionary

func ready():
itemdata = LoadData(“res://text/ItemData.json”)

func LoadData(filepath):
var jsondata
var file_data = File.new()

file_data.open(file_path, File.READ)
json_data = JSON.parse(file_data.get_as_text())
file_data.close()
return json_data.result

and this is the ItemData.json file:
{
“Appel”: {
“ItemCategory”: “Food”,
“StackSize”: 60,
“AddHealth”: 10,
“Description”: “Food is always good”
},
“Stick”: {
“ItemCategory”: “Nature”,
“StackSize”: 60,
“Description”: “Its just a stick… AND YOU CAN CRAFT WITH IT”
}
}

Hey I got same problem too, How can you fix this?

Xenapibe | 2021-08-14 01:54

:bust_in_silhouette: Reply From: Error7Studios
func get_data_dict(filepath: String) -> Dictionary:
	var file := File.new()
	var open_error: int = file.open(filepath, file.READ)
	assert(open_error == OK, str("Invalid filepath: ", filepath))

	var file_text := file.get_as_text()
	var JSON_error_msg: String = validate_json(file_text)
	assert(JSON_error_msg.empty(), str("Invalid JSON: ", JSON_error_msg))

	var JSON_result = parse_json(file_text)
	assert(typeof(JSON_result) == TYPE_DICTIONARY, str("Not a Dictionary: ", JSON_result))

	var dict: Dictionary = JSON_result
	return dict


func _ready():
	var item_dict := get_data_dict("res://text/ItemData.json")

no its not like that on the tutorial

Castor1010 | 2021-02-17 15:52

:bust_in_silhouette: Reply From: Xenapibe

Hey I got same problem too, How can you fix this?
And im following this tutorial too : https://www.youtube.com/watch?v=g1x8ct2Slok&t=159s
I have been working of this warning about 3 days but I can’t find a solution.
So guys please help me.