Using jsondecode function.

291 views
Skip to first unread message

XDC

unread,
Aug 28, 2019, 5:13:24 AM8/28/19
to Automate
First, I want to tell you I am not an programming guy.
Now to the point. I created a flow which allows user to configure it. This takes a lot of variables which is stored in atomic blocks. I used several atomic block to store and load this variables. However, this values are not persistent so a config file is a good choice to store & read this variables.
I have now learnt to use jsonencode to store values in a text file. The problem is I don't know how to read the configuration file and assign the variables.
For example : My config file has this content: {"resx":1020,"resy":1000,"choice":1}
In automate: File read text > file - config.txt, encoding - UTF - 8, output variable - uconfig
                   Variable set > Variable - uconfig, value = jsondecode(uconfig)
Next - ?
Now, how am I supposed to assign the value of this "resx" i.e 1020 to a new variable?
I hope you understand what I am trying to tell. And I apologize for my bad english.

Patrick Corgan

unread,
Aug 28, 2019, 1:35:45 PM8/28/19
to Automate
After you decode the JSON object, you have the same dictionary that you encoded. To read the value of a dictionary key, put the name of that key in quotes inside square brackets after the name of the dictionary.

After what you have:
uconfig["resx"] = 1020

This flow might help:
https://llamalab.com/automate/community/flows/30855

delfa...@gmail.com

unread,
Aug 29, 2019, 12:52:08 AM8/29/19
to Automate
@Patrick Corgan

Thank you! Now I understand what I had to do. Super helpful flow.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages