Is there any specific set of rules or techniques for building JSON reports? I've been developing my own, as I've had to output some pretty complex reports the last week or two. So far, I've discovered the following methodology, when writing reports to be encoded with json_encode();
General Rules:
1) If you don't want to encase a number within quotes, cast it as an integer or a double. Example: $array[1]=(integer)$val;
2) If you want to associate one value to another, set an array key to match the value. Example: $array[bob]="fred"; will equate to JSON code "bob": "fred"
3) If you don't want to associate a value to a value in JSON, use array_push() or array_unshift() to push the value to the bottom or top of the array.
Methodology:
Because json_encode() processes multidimensional arrays, you must build the array structure from the bottom up. In other words, identify what are your lowest building blocks, whether arrays or raw data. Compile them into arrays, then work on the next higher level of arrays, using the data you just compiled. Keep doing so, until you reach the final top_level array, which is when you use json_encode().
This is just some general guidelines I've personally developed, but I was wondering if there are more specific guidelines or rules out there...