Create,Edit,delete and view Json data

Post your questions and help other users.

Moderator: Martin

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: Create,Edit,delete and view Json data

Post by Micky Micky » 26 Dec 2019 15:35

I used trial and error.
The problem is always deciphering the structure that the author used.

For example, this API's response to a HTTP REQUEST was bewildering. I wanted the line name and status. e.g. Bakerloo - Severe Delays

https://api.tfl.gov.uk/line/mode/tube,o ... ail/status

Whereas this API response was easy:

https://official-joke-api.appspot.com/random_joke

I'm using JSON more and more now instead of simple lists as it seems for flexible. I'm happy to help but I'm still learning too.

Good luck
Crude but it works.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Create,Edit,delete and view Json data

Post by Desmanto » 28 Dec 2019 20:02

You don't have to do trial and error. When using debug dialog, you can always browse to the converted JSON, as shown in here : viewtopic.php?f=5&t=8429&p=26494&hilit=json#p26501
Just check if it is a map, then use the key. If it is list, use numbering shown. Debug dialog is one of the best feature to help us creating the flow.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: Create,Edit,delete and view Json data

Post by Micky Micky » 28 Dec 2019 21:01

Yes, trial and error using DEBUG DIALOG. Without that it's impossible. Thanks for highlighting that.

Whilst you're here, I found it impossible to add to a JSON object. For example, adding another entry to the tasks example above. Any help would be appreciated.

Edit:
IT'S OKAY, I FOUND THE ANSWER ON THE FORUM. SOMEONE CALLED DESMANTO EXPLAINED IT PERFECTLY!

Many thanks
Last edited by Micky Micky on 29 Dec 2019 14:42, edited 1 time in total.
Crude but it works.

User avatar
Rafi4
Posts: 281
Joined: 01 Dec 2017 05:23

Re: Create,Edit,delete and view Json data

Post by Rafi4 » 29 Dec 2019 03:09

Hi Micky Micky
In this below example I want to get elements

which contains "Alert":"weekly".
Is this possible? If yes how can I?

[
{
"Task time": 1577384400000,
"Task note": "Break file flow",
"Alert": "weekly"
},
{
"Task time": 1577925900000,
"Task note": "Make a call to parents",
"Alert": "weekly"
},
{
"Task time": 1592095500000,
"Task note": "happy birthday",
"Alert": "yearly"
},
{
"Task time": 1593478800000,
"Task note": "Happy wedding anniversary",
"Alert": "yearly"
}
]

Thanks from record4
No.1 Automation app in play store Automagic Premium
Samsung Galaxy j2 non rooted.
Android 5.1.1

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: Create,Edit,delete and view Json data

Post by Micky Micky » 29 Dec 2019 11:28

Code: Select all


tasksList = '{"tasks":[{"Task time":1577384400000,"Task note":"Break file flow","Alert":"weekly"},{"Task time":1577925900000,"Task note":"Make a call to parents","Alert":"weekly"},{"Task time":1592095500000,"Task note":"happy birthday","Alert":"yearly"},{"Task time":1593478800000,"Task note":"Happy wedding anniversary","Alert":"yearly"}]}';
extractedList = newList ();
js = fromJSON (tasksList);
len = length (js["tasks"]);
search = "weekly";
for (i in [0 to len - 1])
{
alert = js["tasks"][i]["Alert"];
if (matches (search, alert))
{
addElement (extractedList, js["tasks"][i]["Task time"]);
addElement (extractedList, js["tasks"][i]["Task note"]);
}
};
Hope this helps.
Crude but it works.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Create,Edit,delete and view Json data

Post by Desmanto » 29 Dec 2019 19:10

@Micky : Oh, I thought you use bruteforce to find the key :D
Do you mean to add another list/map to the json? I would convert the json to map/list first, add the map/list to the correct path and then convert it back to JSON. But it seems you have found my other post then.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: Create,Edit,delete and view Json data

Post by Micky Micky » 29 Dec 2019 19:32

Yeah, even with DEBUG DIALOG I was still a bit brutal in my ways.

I found that post and it's working great.
I've got a lot of 'crude' to change now!

Thanks very much.
Crude but it works.

User avatar
Rafi4
Posts: 281
Joined: 01 Dec 2017 05:23

Re: Create,Edit,delete and view Json data

Post by Rafi4 » 29 Dec 2019 22:24

Hi Micky Micky
Working Amazing. Thanks a lot.


Happy new year to Martin and all from record4
No.1 Automation app in play store Automagic Premium
Samsung Galaxy j2 non rooted.
Android 5.1.1

User avatar
Rafi4
Posts: 281
Joined: 01 Dec 2017 05:23

Re: Create,Edit,delete and view Json data

Post by Rafi4 » 30 Dec 2019 08:57

Hi Micky Micky and all
How can I get contact name using action
Init Variables Contact Info: Name {phone_number} in json format {contact_info,jsonformat}


thanks from record4
No.1 Automation app in play store Automagic Premium
Samsung Galaxy j2 non rooted.
Android 5.1.1

Micky Micky
Posts: 179
Joined: 16 Oct 2019 17:38

Re: Create,Edit,delete and view Json data

Post by Micky Micky » 30 Dec 2019 09:25

I used this:
Screenshot_20191230-091540.jpg
Screenshot_20191230-091540.jpg (248.46 KiB) Viewed 16676 times
It returned 'contact_info' which is already a JSON object. The name was in three places. I think the first one is all you need.

Code: Select all

displayName = contact_info["display_name"];
a = contact_info["structured_name_list"][0]["display_name"];
b = contact_info["structured_name_list"][0]["given_name"];
I'm going to post a link to a forum post by Desmanto that explains creating and editing your own JSON objects. It's helped me a lot. I think it will be helpful for you.
Crude but it works.

Post Reply