If you’re designing an API (and returning JSON, or even JSONP) you should consider the content type as well.
Here’s a design that renders JSON, and when passed a “callback” parameter will render JSONP with the parameter value as the function name
<MySource_AREA id_name="get_vars" design_area="request_vars">
<MySource_SET name="method" value="get" />
</MySource_AREA>
<MySource_AREA id_name="content_type_start" design_area="show_if">
<MySource_SET name="condition" value="keyword_regexp"/>
<MySource_SET name="condition_keyword" value="globals_get_callback"/>
<MySource_SET name="condition_keyword_match" value=".+"/>
<MySource_THEN>
<MySource_print id_name="__global__" var="content_type" content_type="application/javascript" />
<MySource_print id_name="get_vars" var="callback"/>(
</MySource_THEN>
<MySource_ELSE>
<MySource_print id_name="__global__" var="content_type" content_type="application/json" />
</MySource_ELSE>
</MySource_AREA>
<MySource_AREA id_name="page_body" design_area="body"/>
<MySource_AREA id_name="content_type_end" design_area="show_if">
<MySource_SET name="condition" value="keyword_regexp"/>
<MySource_SET name="condition_keyword" value="globals_get_callback"/>
<MySource_SET name="condition_keyword_match" value=".+"/>
<MySource_THEN>);</MySource_THEN>
</MySource_AREA>
Since we need a comma between each element in the list, but not after the last we can use the position format feature in Matrix. With a little bit of thought we can also get it so we don’t need to update the formats separately!
On the Display Formats screen of the asset listing, create a customised format for position -1, and fill this in as though there’s only a single instance of this type. Then, link this bodycopy div under the default format, and add a new div in the default format just for the separating comma!
This way you only have to edit one of the type formats and they’ll all get the same changes.
It’s also best to have a customisation each for logged out and logged in, so that you can provide some useful content when an unauthorised request is made.