aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions.rsc
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2023-10-10 12:08:17 +0200
committerGravatar Christian Hesse <mail@eworm.de>2023-10-16 11:51:04 +0200
commit080b3cbf9d8ff6cde9aeb08650ead5c3eeb9e7b7 (patch)
treed63edc46ef738c7957dd8e1fef9e11a8f446cca5 /global-functions.rsc
parent8e9734347e365f9a801096664c27bf0f76d0bc4e (diff)
global-functions: make $ParseJson global
Diffstat (limited to 'global-functions.rsc')
-rw-r--r--global-functions.rsc29
1 files changed, 29 insertions, 0 deletions
diff --git a/global-functions.rsc b/global-functions.rsc
index 8c96c72..80f1f78 100644
--- a/global-functions.rsc
+++ b/global-functions.rsc
@@ -48,6 +48,7 @@
:global MkDir;
:global NotificationFunctions;
:global ParseDate;
+:global ParseJson;
:global ParseKeyValueStore;
:global PrettyPrint;
:global RandomDelay;
@@ -694,6 +695,34 @@
"day"=[ :tonum [ :pick $Date 8 10 ] ] });
}
+# parse JSON into array
+# Warning: This is not a complete parser!
+:set ParseJson do={
+ :local Input [ :toarray $1 ];
+
+ :local Return ({});
+ :local Skip 0;
+
+ :for I from=0 to=([ :len $Input ] - 1) do={
+ :if ($Skip > 0 || $Input->$I = "\n" || $Input->$I = "\r\n") do={
+ :if ($Skip > 0) do={
+ :set $Skip ($Skip - 1);
+ }
+ } else={
+ :local Key ($Input->$I);
+ :if ($Input->($I + 1) = ":") do={
+ :set ($Return->$Key) ($Input->($I + 2));
+ :set Skip 2;
+ } else={
+ :set ($Return->$Key) [ :pick ($Input->($I + 1)) 1 [ :len ($Input->($I + 1)) ] ];
+ :set Skip 1;
+ }
+ }
+ }
+
+ :return $Return;
+}
+
# parse key value store
:set ParseKeyValueStore do={
:local Source $1;