We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38136
    • 42 Posts
    Hi Community.

    i encountered a problem with a snippet where i am sending data as a JSON formated string. i am using caching. In fact the JSON has a depth of 5 level everythings looks as it should in the cache file.

    if i return the cachefile it somehow gets altered. if there are more then 5 curly closed brackets in a row they get changed to one 1 squared closed bracket.

    which of course is breaking my JSON.

    i could simulate the behaviour like the following:

    <?php if(time() > 1471384800){return null;} return '}}}}}';
    


    they output always is:

    ]
    


    or

    <?php if(time() > 1471384800){return null;} return '}}}}}}}';
    


    corresponds to:

    ]}}
    


    is it a bug of modx? i am using 2.5.0pl with a LAMP installation.

    any ideas?

    greetings
      • 3749
      • 24,544 Posts
      I'm not sure it makes any difference, but are you using $modx->toJSON() and $modx->fromJSON() to do the conversions, or just PHP's functions?
        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
        • 38136
        • 42 Posts
        i am using the PHP functions. wasnt aware that there are modx functions available.

        i also figured out that. when i am doing it in my Template {{{{{ }}}}} without any JSON. It ll be converted to [ ].
          • 38136
          • 42 Posts
          well, i figured out that it is not a problem of the modx core. it seems to be a problem with a module that i am using, presumable pdoTools.
            • 4172
            • 5,888 Posts
            try to disable the fenom-parser in the system-settings
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 38136
              • 42 Posts
              it is already disabled. the behaviour is still as mentioned.

              i ve a workaround. i am using a snippet and instead of returning the json string i am doing the following:

              /* workaround for curly bracket trouble {{{{{ }}}}}*/
              header('Content-Type: application/json');  
              die($output);
              


              well, in my case where i just need to have a json-only-http-response it is running. for inline json, that's still troublesome and the workaround is not a solution.
                • 3749
                • 24,544 Posts
                Can you put that directive in the JS file that receives the data?

                Also, I wonder if the JSON_FORCE_OBJECT option for json_encode() would help.
                  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
                  • 38136
                  • 42 Posts
                  well, it is not the js file that recieves the data. it is the data deliverer. so no problem in fact.

                  the json isn't the problem at all. it is properly generated. coz i am using caching, so i was able to figure out that the return string of the cache file was properly.

                  just the template parsing seems to be the problem. as i see so far is the problem also when i put the five curly brackets in a template (guess also chunk, but i didnt tried that yet) they will be translated to an opened or closed squared bracket coresponding to the curly brackets.
                    • 3749
                    • 24,544 Posts
                    I'm not sure what your flow is, but maybe you could use some other symbol there and translate it before it's used. Another option might be to escape it ( \} ) or quote it (or quote the whole string).
                      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