Saving Json as File And Reading it as Dictonary

Hi All :slight_smile: ,
Can someone please help me out…
I am saving a Dictonary in a txt file :

But When I read from this file after saving :


It shows False. And hence I can’t use it as Dictonary (which I want to use as) Please someone let me know how to fix that.

Ate you sure your the method of dictionary creation is valid? Not sure it seems… instead of saving those values as a text , catch it on a label or something else to verify your work is correct…

Actually here you should place the dictionary varuvala i hope

1 Like

Hi @Still-learning.
Ya my mistk But Same Result.

The Saved file is saving that accurately. See :

I Even Tried This :

And When “Do it” on this :

Still Show False.

I think, This is same as this:
As this also shows False

I mean :
This Block Returns The Result as String. And hence It is not considered as dictonary…

But, Now what Can be solution of this?

Could you please post your json here ?

Hi, @dora_paz Ncy to see you here,…
I am storing the data entered by the user on the runtime. Like this :

But, I think problem is this :

And one more thing, When I store the same data in TinyDB, And Get it back It shows True.(i.e. The result is dictonary).

Correct, when the json is saved to a file it is saved as text (JSON.stringify()). You will need to parse the JSON string with the correct block to get it back as a dictionary.

Hi @TimAi2, Can you please guide me how to do that?

What happens if you use web component json text decode block to read result?


I am trying…

@dora_paz has suggested correctly :slight_smile:

I used a label to replicate the file i/o

It is confusing because they look the same, but one is a string, the other is an object (a dictionary / list)

It works with tinydb because tinydb saves the dictionary as an object and returns it as an object (even though it looks like a string :slight_smile: ). tinydb does the same with saved lists.

1 Like

Also since this block is available only in MIT App Inventor use

1 Like

oh yes, oops :wink:

1 Like

Thanks @dora_paz and @TimAi2 , That Solved the Problem.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.