+2 votes

Hi!
I have a string which is like this "{"apple" : 20, "mango" : 25}" and I want to convert it into the dictionary as the dictionary is clearly visible in it

Godot version v3.2.3-stable_win64
in Engine by (884 points)

2 Answers

–1 vote
Best answer

You are trying to parse a JSON string into a dictionary.
When looking for an answer always pay attention to the right words, it will help you a lot with your programming.

If you check this thread
https://godotengine.org/qa/8291/how-to-parse-a-json-file-i-wrote-myself

I think the most voted answer (the one for Godot 3) is the one that suits you.

by (290 points)
selected by

First of all Sorry for repeating question just i was not getting right words.
Actually I was doing this

var dict = {"apple" : 20, "mango" : 25}
var string_of_dict = str(dict)
#now I want it to convert into dictionary again

Downvote for talking around and not giving the right answer or example.
And the question contains the right words.

User was directed to an existing good answer with explanation of the right words to use to describe the problem. User chose the answer as suitable. Maybe I talked around too much but the problem was solved when it was raised.

+1 vote
parse_json(my_string)

or

JSON.parse(my_string)

should create a dictionary

by (25 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.