I am using a json file to map out screens on my project. This reduces 50+ screens down to 6. This works fine when I have the json file saved in Firebase but I would like to have this parsed/worked with locally in app.
The issue is to do with the key. I am unsure how to change the key value locally whenever the screen opens.
I can achieve what I want using Firebase, as I just change the key input by joining the previous key, a forward slash and the new object name (originalObject --> originalObject/newObject), but I can’t seem to do the same with a variable that contains the json file locally.
Maybe I’ve missed something. Could I use the join block with “/” like in Firebase, or is this specific to Firebase as it saves different objects under a “/” in the url.
I don’t totally understand what you are trying to do…
Could you share a screen shot of what you expect to work and is not?
If I understand correctly, you have a text field that contains JSON data. In Firebase, you use “/” to create a path, but this method is not suitable for getting paths in local JSON. You need to explicitly specify a reference to the original parent object and then a reference to its child object. Blocks for working with objects allow you to set key names using variables
Please note that the palette also has a unit to get all of the names of child keys for the selected parent object.
Hi @darren and @actech, thank you both for your replies.
Darren, I really should have included screenshots but I didn’t know exactly what to include. I think my problem was explaining the problem. Actech did a much better job of explaining it. I’m displaying objects in a list, and when I click on the list item, it grabs that objects children and repeats the process.
Actech, yes this is what I am doing. When I change the key (setting the new variable with a “/” for Firebase) could I replace this part with the getObject block. Changing the key only ever jumps one step at a time, or gets the child objects, never twice or more. Could I keep changing a variable like this?
The way I would like this to work is so that the screen always displays the parent objects as a list, and when I click on one of these list items, it get’s it’s child properties and then repeats the process.
Again thank you both for getting back to me, much appreciated.
Your data structure has a tree structure. To bypass it, you can use recursion with the condition: get child objects as long as a non-empty list of properties is returned for the current node.
At the debugging stage, use a variable with the maximum recursion value, for example, 20, to protect against infinite recursion and application freezes. in each iteration, reduce it and check if it is equal to 0, it means that there is an error and you need to abort the recursive function.
Thank you for your help on this, I really appreciate it. I got this method to work using get property of object. Here are the blocks:
This only works when getting 1 property at a time, but it is exactly what I want. I’ve marked this as the solution if anybody searches this topic looking for the blocks, but read up if you want to understand why this is the solution.
These blocks exclude a very strict set of if statements to tell the app if it should end the process. In my JSON, I have indicated that this should end by setting the value to “END”.