Create,Edit,delete and view Json data

Post your questions and help other users.

Moderator: Martin

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

Create,Edit,delete and view Json data

Post by Rafi4 » 24 Dec 2019 03:21

Hi all
I want a simple example flow how to create ,Edit, Delete and view Json data
I am in a bit confusion about json.
Thanks in advance for post.

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

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

Re: Create,Edit,delete and view Json data

Post by Desmanto » 24 Dec 2019 18:19

What kind of json data you need to work with? It is a good practice to always use fromJSON() and toJSON() to convert json first to object, edit it and then convert back to json afterward.

You can search the forum for various usage example
viewtopic.php?f=5&t=8458&p=26620&hilit=json#p26620
viewtopic.php?f=5&t=8429&p=26493&hilit=json#p26493
viewtopic.php?f=5&t=8393&p=26297&hilit=json#p26297
But most json need is unique, so need to see the structure first.
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 » 24 Dec 2019 19:05

Desmanto is right.

I use JSON a lot now getting data from APIs. They are all structured differently. But with DEBUG DIALOG and plenty of trial and error you can get the data you want.

Good luck
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 » 25 Dec 2019 01:56

Hi Desmanto
Hi I have already tried this. But I am still in confusion how to create,view,delete and edit data?

In this below example how can I get all names values in a list and how to enter,edit and delete data?


peopleList =
'{"people" :[{"name":"Micky","phone":"012345678","birthday":"0101"},{"name":"Mickey","phone":"12345678","birthday":"0202"},{"name":"Michael ","phone":"2345678","birthday":"0303"},{"name":"Micheal","phone":"345678","birthday":"0404"},{"name":"Mike","phone":"567890","birthday":"0505"}]}';


js = fromJSON (peopleList);
len = length (js["people"]);
name = js["people"][a]["name"];
phone = js["people"][a]["phone"];
birthday = js["people"][a]["birthday"];



Thanks a lot 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 » 25 Dec 2019 06:07

peopleList =
'{"people" :[{"name":"Micky","phone":"012345678","birthday":"0101"},{"name":"Mickey","phone":"12345678","birthday":"0202"},{"name":"Michael ","phone":"2345678","birthday":"0303"},{"name":"Micheal","phone":"345678","birthday":"0404"},{"name":"Mike","phone":"567890","birthday":"0505"}]}';

js = fromJSON (peopleList);
len = length (js["people"]);
extractedList = newList ();
for (a in [0 to len - 1])
{
name = js["people"][a]["name"];
addElement (extractedList, name);
js["people"][a]["name"] = "Santa Claus {a+1}"
}
peopleList = toJSON(js);


Merry Christmas
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 » 26 Dec 2019 05:50

Hi all
In this below example json script how can I access all values in one loop?
Task time, Task note, Alert values in one loop.
[
{
"Task time": 1577340000000,
"Task note": "Backup flow",
"Alert": "weekly"
},
{
"Task time": 1577370840000,
"Task note": "Calls logging flow",
"Alert": "daily"
},
{
"Task time": 1577384400000,
"Task note": "Break file flow",
"Alert": "weekly"
},
{
"Task time": 1577424600000,
"Task note": "Filter palm oil",
"Alert": "daily"
},
{
"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"
}
]

from record4 thanks a lot
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 » 26 Dec 2019 07:19

Firstly, I couldn't copy your data. It was giving me formatting problems. I think it's where you laid in a JSON style structure. Using DEBUG DIALOG click on js and view as JSON and you'll see the data below presented in a JSON style structure.

So here it is with just 2 entries.

Hope this helps


extractedList = newList ();

MyTasks =
'{"tasks" :[{"Task time":1577340000000,"Task note":"Backup flow","Alert":"weekly"},{"Task time":1577370840000,"Task note":"Calls logging flow","Alert":"daily"}]}';

js = fromJSON (MyTasks);
len = length (js["tasks"]);

for (i in [0 to len - 1])
{
frequency = js["tasks"]["Alert"];
addElement (extractedList, frequency);
}
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 » 26 Dec 2019 10:35

Hi Micky Micky

I want to get all values in one loop not only one.
Alert ,Task time and Task note all values


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 » 26 Dec 2019 11:34

Just add more queries to the loop.
Also, there was an error in what I posted before.
Which I now see is caused when I paste into this window.
Disable BBCode got rid of the problem.


extractedList = newList ();

MyTasks =
'{"tasks" :[{"Task time":1577340000000,"Task note":"Backup flow","Alert":"weekly"},{"Task time":1577370840000,"Task note":"Calls logging flow","Alert":"daily"}]}';

js = fromJSON (MyTasks);
len = length (js["tasks"]);

for (i in [0 to len - 1])
{
time = js["tasks"][i]["Task time"];
addElement (extractedList, time);
note = js["tasks"][i]["Task note"];
addElement (extractedList, note);
frequency = js["tasks"][i]["Alert"];
addElement (extractedList, frequency);
}
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 » 26 Dec 2019 14:07

Hi Micky Micky
Thanks a lot. Where can I learn more information about json ?

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

Post Reply