From 1d055261b4144dbf86b2658437015b15d4dd9bff Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 4 Sep 2022 00:32:56 +0100 Subject: initial --- examples/example4.csd | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 examples/example4.csd (limited to 'examples/example4.csd') diff --git a/examples/example4.csd b/examples/example4.csd new file mode 100644 index 0000000..b6bc78c --- /dev/null +++ b/examples/example4.csd @@ -0,0 +1,57 @@ +/* + csound-json example 4 + + fill JSON object with various data at init time + +*/ + + + Released into the public domain under the Unlicense license + http://unlicense.org/ + + +-d +-m0 + + +sr = 44100 +ksmps = 64 +nchnls = 2 +0dbfs = 1 + + +instr boot + + ; empty object + iJson jsoninit + + ; add key/value combination as "description" object + Skeys[] fillarray "colour", "taste", "smell" + Svalues[] fillarray "blue", "sweet", "vile" + iJsonSub1 jsoninit + jsoninsertval iJsonSub1, Skeys, Svalues + jsoninsert iJson, "description", iJsonSub1 + + ; add key/value combination and additional value to iJsonSub2 + Skeys[] fillarray "height", "width" + ivalues[] fillarray 35.4, 6.41 + iJsonSub2 jsoninit + jsoninsertval iJsonSub2, Skeys, ivalues + jsoninsertval iJsonSub2, "depth", 16.439 + + ; add iJsonSub2 to array along with new specified string objects + iJsonObjects[] fillarray iJsonSub2, jsonloads("{\"not\": \"much\"}"), jsonloads("[1,2,3]") + + ; add all of the above iJsonObjects back into the main object under "measurements" key + jsoninsert iJson, "measurements", iJsonObjects + + ; show the result + prints sprintf("%s\n\n", jsondumps(iJson)) +endin + + + + +i"boot" 0 1 + + \ No newline at end of file -- cgit v1.2.3