Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 182 lines (182 sloc) 5.885 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
#N canvas 44 51 994 506 10;
#X obj 566 321 json-encode;
#X obj 566 390 json-decode;
#X obj 47 -14 json-encode;
#X obj 47 14 json-decode;
#X text 127 -13 - encodes data into a JSON string.;
#X text 127 13 - decodes a JSON string to lists.;
#X text 47 46 [json-encode] has three methods: add \, clear and bang.
add adds a new key/value pair to the internally stored object. clear
clears the internally stored object. bang outputs the stored object
as a JSON string. If you call add with a value that is already a JSON
string \, then the object will be added as a nested object.;
#X msg 548 57 add id 1;
#X text 545 24 Will add key id and value of 1 to object;
#X msg 590 87 add name Residuum;
#X msg 616 141 add album Der Diskokeller des Grauens;
#X text 616 113 This will add a string with the spaces intact to the
JSON object;
#X msg 636 172 add year 2011;
#X msg 654 229 add id 2;
#X text 651 202 adding a different value will overwrite the previously
stored one;
#X msg 363 271 clear;
#X text 359 252 This will clear the object;
#X text 696 263 output the value;
#X msg 697 282 bang;
#X obj 656 391 print JSON string;
#N canvas 91 51 453 402 nested-objects 0;
#X obj -74 -56 json-encode;
#X obj -74 2 json-decode;
#X msg 104 -101 add name Residuum;
#X msg -74 -103 bang;
#X obj 11 2 print JSON string;
#X obj -8 -147 json-encode;
#X msg -8 -181 add album Der Diskokeller des Grauens \, add year 2011
\, bang \,;
#X msg -8 -101 add newest \$1;
#X obj -74 -274 bng 15 250 50 0 empty empty Click_to_create_a_nested_object
17 7 0 10 -262144 -1 -1;
#X obj -74 -244 t b b b;
#X obj -74 42 print pair;
#X obj -3 42 print decoding done;
#X obj -74 -30 t a a;
#X connect 0 0 12 0;
#X connect 1 0 10 0;
#X connect 1 1 11 0;
#X connect 2 0 0 0;
#X connect 3 0 0 0;
#X connect 5 0 7 0;
#X connect 6 0 5 0;
#X connect 7 0 0 0;
#X connect 8 0 9 0;
#X connect 9 0 3 0;
#X connect 9 1 6 0;
#X connect 9 2 2 0;
#X connect 12 0 1 0;
#X connect 12 1 4 0;
#X restore 57 429 pd nested-objects;
#X obj 697 427 print decoding done;
#X obj 566 427 print decoded values;
#X obj 566 348 t a a;
#N canvas 318 51 693 648 about-decoded-json-strings 0;
#X obj 218 -185 json-encode;
#X obj 94 -86 json-decode;
#X msg 218 -232 bang;
#X obj 303 -127 print JSON string;
#X obj 218 -382 bng 15 250 50 0 empty empty Click_to_create_an_object
17 7 0 10 -262144 -1 -1;
#X obj 218 -352 t b b b b;
#X msg 269 -316 add duration 3000;
#X obj 218 -159 t a a a;
#X obj 255 -89 json-decode;
#X obj 255 55 line;
#X floatatom 255 88 5 0 0 0 - - -;
#X msg 255 35 \$1 \, \$2 \$3;
#X obj 255 -30 route start end duration;
#X text 264 -110 wrong;
#X obj 94 72 line;
#X floatatom 94 105 5 0 0 0 - - -;
#X obj 94 -29 route start end duration;
#X text 105 -121 right;
#X obj 94 -58 list trim;
#X obj 255 -59 list trim;
#X obj 255 13 pack 0 0 0;
#X msg 252 -286 add start 100;
#X msg 235 -255 add end 500;
#X obj 79 1 f;
#X obj 94 30 pack 0 0 0;
#X msg 94 52 \$1 \, \$2 \$3;
#X text -178 -316 This will give you a chance to wait fotr other data
from the JSON object.;
#X text -179 -398 You should not assume too much about the order of
keys and values in a JSON object. In this example \, a JSON string
is decoded to drive a [line] object from start to stop using [route]
and [pack]. When using [pack] you should not feed the left-most inlet
with data immediately \, but store a value \, e.g. in a [f] and bang
the store \, with the right outlet of [json-decode] or [rest-json].
;
#X connect 0 0 7 0;
#X connect 1 0 18 0;
#X connect 1 1 23 0;
#X connect 2 0 0 0;
#X connect 4 0 5 0;
#X connect 5 0 2 0;
#X connect 5 1 22 0;
#X connect 5 2 21 0;
#X connect 5 3 6 0;
#X connect 6 0 0 0;
#X connect 7 0 1 0;
#X connect 7 1 8 0;
#X connect 7 2 3 0;
#X connect 8 0 19 0;
#X connect 9 0 10 0;
#X connect 11 0 9 0;
#X connect 12 0 20 0;
#X connect 12 1 20 1;
#X connect 12 2 20 2;
#X connect 14 0 15 0;
#X connect 16 0 23 1;
#X connect 16 1 24 1;
#X connect 16 2 24 2;
#X connect 18 0 16 0;
#X connect 19 0 12 0;
#X connect 20 0 11 0;
#X connect 21 0 0 0;
#X connect 22 0 0 0;
#X connect 23 0 24 0;
#X connect 24 0 25 0;
#X connect 25 0 14 0;
#X restore 173 430 pd about-decoded-json-strings;
#X text 46 114 [json-decode] will accept a JSON string at its input
and will output the decoded object as a series of lists of key/value
pairs. Boolean values of TRUE/FALSE will be translated to 1 or 0 \,
float and integer values will be output as floats. Json-decode will
try to convert string values to floats \, and if that fails \, will
output them as symbols \, nested objects and arrays are output as strings
\, that can be parsed. After the object is fully parsed \, the right
outlet will issue a bang \, so that you can differenciate between subsequent
objects. The messages will come as list key value.;
#N canvas 44 51 450 465 json-arrays 0;
#X obj 42 73 json-encode;
#X msg 42 33 clear \, array storage textfile \, array storage couchdb
\, array storage array \, bang;
#X obj 42 154 json-decode;
#X obj 42 112 t a a;
#X text 49 11 This will construct a json array.;
#X obj 42 191 list trim;
#X obj 42 224 route storage;
#X obj 42 255 l2s;
#X obj 42 313 json-decode;
#X obj 42 280 t a a;
#X obj 127 313 print JSON array string;
#X obj 132 155 print JSON object string;
#X obj 105 349 print array member done;
#X obj 42 374 print decoded;
#X connect 0 0 3 0;
#X connect 1 0 0 0;
#X connect 2 0 5 0;
#X connect 3 0 2 0;
#X connect 3 1 11 0;
#X connect 5 0 6 0;
#X connect 6 0 7 0;
#X connect 7 0 9 0;
#X connect 8 0 13 0;
#X connect 8 1 12 0;
#X connect 9 0 8 0;
#X connect 9 1 10 0;
#X restore 364 430 pd json-arrays;
#X text 46 232 [json-decode] treats json arrays as a series of objects.
;
#X connect 0 0 23 0;
#X connect 1 0 22 0;
#X connect 1 1 21 0;
#X connect 7 0 0 0;
#X connect 9 0 0 0;
#X connect 10 0 0 0;
#X connect 12 0 0 0;
#X connect 13 0 0 0;
#X connect 15 0 0 0;
#X connect 18 0 0 0;
#X connect 23 0 1 0;
#X connect 23 1 19 0;
Something went wrong with that request. Please try again.