Does anyone have a simple explanation for what json_encode does with img tags? Alternatively, if I want to pass an img tag through json_encode, what do I need to do to get it successfully through json_encode?
It’s just encoding the supplied data as JSON, in the case of HTML it’s a string so it escapes any characters in HTML that need to be escaped in JSON will be escaped with a backslash.
Most html tags are escaped, but not img tags from what I can see. I’m working with a JSON feed of assets where the html is being passed through the json_encode modifier, and the img tag is not coming through in the JSON feed.
From a bit of testing via wrapping img tags in comments, it looks like the json_encode modifier is discarding them? E.g. if I have the following in output html (via a paint layout)
and then ^json_encode that content (in this case using %asset_contents_paint_44855^replace:[\r\n\t]:^replace: +: ^json_encode%) the JSON output only contains:
I guess it depends on the full format of the string you pass to json_decode right? As in, you can’t really pass it HTML and get a JSON object out of it. It already has to be in a JSON or array string for it to work.