I do not know how to do this directly from your object without any auxiliary variables. Here's what you CAN do before passing data to the template, to avoid having to bind to the code that generates the original JSON object.
Let it be your JSON object:
var data = { test: [ "test1", "test2", "test3" ] }
Let it be your mustache pattern:
{{#isArray}} {{#test}} <li>{{.}}</li>{{/test}} {{/isArray}} {{^isArray}} {{test}} {{/isArray}}
Let it be your code that compiles / calls your mustache pattern (I use document.body.innerHTML, because that's how I created the JSFIDDLE example):
var template = document.body.innerHTML; document.body.innerHTML = Mustache.render(template, data);
In the above setup, the following will be displayed: isArray is undefined, so it will execute a block that cancels isArray using the ^ character (for example, it will process the data as a string, even if it is an array):
test1,test2,test3
I suggest, if you do not want to touch the code that generates JSON, that you add some javascript before calling Mustache.render to set the isArray property. Here's how I would check for the existence of the pop method in order to set isArray correctly before passing data to the template:
if (data.test.pop) { data.isArray = 1; } else { data.isArray = 0; } var template = document.body.innerHTML; document.body.innerHTML = Mustache.render(template, data);
This will correctly print the desired li elements:
test1 test2 test3
I gave a working example here that uses both an array and string instances in a data element to show that the solution works:
http://jsfiddle.net/s7Wne/1/