I am using the Craft Prune plugin (https://github.com/mattstauffer/craftcms-prune) to pull out a JSON array of entries from a section of my site with the aim of integrating the data into a typeahead search field as autocomplete data.

The problem I seem to be having is that the JSON array structure needs to be simplified for use as a datasource with typeahead.

So the current JSON data structure is:

[{"title":"Entry One Title"}, {"title":"Entry Two Title"}, {"title":"Entry Three Title"}]

What I actually need the structure to be is:

["Entry One Title", "Entry Two Title", "Entry Three Title"]

I have already tried using the jQuery $.each() function and the jQuery $.map() function but they both simply return an array of objects not a simple JS array.

Any help appreciated.

1 Answer 1


Ended up working out a solution:

var myData = {{ craft.entries.section('sectionName').find() | prune(['title']) | json_encode() | raw  }};
    var myArray = $.makeArray(myData);
    var newArray = new Array();
    $.each( arr, function(key, value) {
        $.each(value, function(keyNew, valueNew){

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.