Is it possible to read a json file, look for a key, replace its value and (over)write only that new value for that particular key in the file?
Thanks!
json file
Moderator: Martin
Re: json file
If you want only to replace text, just use replace() function and treat it like a usual text file replacement.
But if you need the specific json key-value replacement, you must convert it first to object, fromJSON(file_text), look for the key, assign new value and then convert it back to json. Automagic support indented function toJSON(file_text, true) or compact toJSON(file_text, false).
Other non destructive method, require specific replace() based on the key value you found and replace manually on the text variable, or probably using regex. Much more complicated. I should have a look on the json example first (censor out any sensitive/private data, if there is)
But if you need the specific json key-value replacement, you must convert it first to object, fromJSON(file_text), look for the key, assign new value and then convert it back to json. Automagic support indented function toJSON(file_text, true) or compact toJSON(file_text, false).
Other non destructive method, require specific replace() based on the key value you found and replace manually on the text variable, or probably using regex. Much more complicated. I should have a look on the json example first (censor out any sensitive/private data, if there is)
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.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
-
- Posts: 69
- Joined: 14 Feb 2019 15:04
Re: json file
Oh, very nice, thank you!
I'll try this probably tomorrow.
I'm trying to move part of the AM flows to the Raspberry Pie, control the lights in some particular and constant scenarios with some motion sensors and luminosity sensors combo, for which I don't really need AM all the way, to lower the load on my phone. And i need to write some config files on the pie with AM, occasionally.
That's why i need base64 and json
I'll try this probably tomorrow.
I'm trying to move part of the AM flows to the Raspberry Pie, control the lights in some particular and constant scenarios with some motion sensors and luminosity sensors combo, for which I don't really need AM all the way, to lower the load on my phone. And i need to write some config files on the pie with AM, occasionally.
That's why i need base64 and json