Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

183 lines (182 sloc) 5.885 kb
#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;
#N canvas 89 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 -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 -74 -30 t a a;
#X obj -3 42 print decoding_done;
#X obj 11 2 print JSON_string;
#X connect 0 0 10 0;
#X connect 1 0 9 0;
#X connect 1 1 11 0;
#X connect 2 0 0 0;
#X connect 3 0 0 0;
#X connect 4 0 6 0;
#X connect 5 0 4 0;
#X connect 6 0 0 0;
#X connect 7 0 8 0;
#X connect 8 0 3 0;
#X connect 8 1 5 0;
#X connect 8 2 2 0;
#X connect 10 0 1 0;
#X connect 10 1 12 0;
#X restore 57 429 pd nested-objects;
#X obj 566 348 t a a;
#N canvas 316 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 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 obj 303 -127 print JSON_string;
#X connect 0 0 6 0;
#X connect 1 0 17 0;
#X connect 1 1 22 0;
#X connect 2 0 0 0;
#X connect 3 0 4 0;
#X connect 4 0 2 0;
#X connect 4 1 21 0;
#X connect 4 2 20 0;
#X connect 4 3 5 0;
#X connect 5 0 0 0;
#X connect 6 0 1 0;
#X connect 6 1 7 0;
#X connect 6 2 27 0;
#X connect 7 0 18 0;
#X connect 8 0 9 0;
#X connect 10 0 8 0;
#X connect 11 0 19 0;
#X connect 11 1 19 1;
#X connect 11 2 19 2;
#X connect 13 0 14 0;
#X connect 15 0 22 1;
#X connect 15 1 23 1;
#X connect 15 2 23 2;
#X connect 17 0 15 0;
#X connect 18 0 11 0;
#X connect 19 0 10 0;
#X connect 20 0 0 0;
#X connect 21 0 0 0;
#X connect 22 0 23 0;
#X connect 23 0 24 0;
#X connect 24 0 13 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 42 374 print decoded;
#X obj 132 155 print JSON_object_string;
#X obj 127 313 print JSON_array_string;
#X obj 105 349 print array_member_done;
#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 10 0;
#X connect 8 1 13 0;
#X connect 9 0 8 0;
#X connect 9 1 12 0;
#X restore 364 430 pd json-arrays;
#X text 46 232 [json-decode] treats json arrays as a series of objects.
;
#X obj 566 427 print decoded_values;
#X obj 697 427 print decoding_done;
#X obj 656 391 print JSON_string;
#X connect 0 0 20 0;
#X connect 1 0 25 0;
#X connect 1 1 26 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 20 0 1 0;
#X connect 20 1 27 0;
Jump to Line
Something went wrong with that request. Please try again.