We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33657
    • 128 Posts
    I am trying to create a json output of all the articles data. When I try and output the articles using [[+articlestags]] its just a string with comma's seperating the items. I looked at the snippet "tolinks" which is great, but I am not much of a php coder.

    If I could do this.

    {
    "tags" : "[[+articlestags]]",
    }

    and have the articlestags output proper json.

    I thought about just making a migxtv variable and forgetting about articles.. i dont use any of the functionality. i just pull all the data and use it in a angular app. but if I did that I might as well just create my own resources and do the whole thing in migx and standard variables..

      • 3749
      • 24,544 Posts
      You could create a custom output modifier in the form of a snippet called ToJSON with this code:

      return $modx->toJSON($input);



      Once that exists, this should work:

      "tags": "[[+articlestags:ToJSON]]",


      If you want your JSON string to represent an array, you'll want this instead in the snippet:

      $code = explode(',', $input);
      return $modx->toJSON($code);


        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 33657
        • 128 Posts
        ug! i gave up shortly after asking the question because there was just too many things I didn't care about, like comments, tagging, archives all that stuff in the Articles admin panel, so i ended up just writing my own pages and using form manager to make them pretty. but Bob, I know your code is going to work because you are the man. So i am going to save your code because I know that I will be doing more JSON stuff in the future with modx and this is just what i needed!

        I was using

        <?php
        //$output = $modx->toJSON($input);
        $output = json_encode($input);
        return $output;


        to turn HTML into json (like escaping tags and etc) so the other snippet you made is great for tags and other things. Thank you!