We've created an asset listing that generates a JSON output. The problem is that we can't escape the quote or backslash characters correctly. We've tried:
[list=1]
%keyword^escapequotes%, which also escapes single quotes and invalidates the JSON. This then fails to parse.
[*]%keyword^[b]escapehtml[/b]%], which doesn't escape the backslash. Fails to parse.
[*]%keyword^replace:":\"%, which holds the most promice doesn't appear to do anything.
So with that out of the way, has anyone got any ideas as to how to escape double-quotes and backslashes in a keyword? Is there a way to specify these non-alpha characters as parameters in the replace keyword?
Hey Ash, this is a tricky one that I ran into the other day as well. In the end I had to switch to XML. Did you try a double-backslash when using the replace modifier?
Creating JSON is tricky anyway, because valid JSON isn't supposed to have trailing commas at the end of arrays and I can't think of a way to achieve this just with an asset listing by itself.
[quote]
Creating JSON is tricky anyway, because valid JSON isn't supposed to have trailing commas at the end of arrays and I can't think of a way to achieve this just with an asset listing by itself.
[/quote]
You can use a position format of -1 to indicate the last asset then use that without the trailing comma. I created valid JSON this way for an internal project that I built…
[quote]
You can use a position format of -1 to indicate the last asset then use that without the trailing comma. I created valid JSON this way for an internal project that I built…
[/quote]
Wow, good tip! I wish I'd thought of that a couple of weeks ago…
I haven't tested the tab replacement yet so it might not be completely working, but it works fine for otherwise escaping characters that fail validation.