I am having trouble visualizing what you are trying, and understanding the context. Piping to safeHTML seems like it should work. When I have generated json in the past, say for a search index, I have used jsonify. You can pipe to multiple functions as well:
I had a feeling I had something in the form of "url": "{{.Site.BaseURL}}" somewhere in my sites, so I went digging, and it looks like behaviour may have possibly changed between 0.54 and 0.55?.
Adding {{.Site.BaseURL | jsonify | safeJS }} is giving me \x22http:\/\/localhost:1313\/\x22 and adding {{ .Site.BaseURL | htmlUnescape | safeHTML }} is giving me http:\/\/localhost:1313\/.
It works for me the way I described above, on 0.55.3. Could you try the example input exactly? If you are getting different results, do you have a repo or a minimal example we can look at to test?
@akshaybabloo The same situation. I changed from 0.54 to 0.55 and there were backslash in url inside the scripts. It took me hours to find this thread.
Very confusing to use it without " "
Anyway "url": {{ .Site.BaseURL }}, works. But I still think it is a bug
If I need something like this: "url": "{{ .Site.BaseURL }}/hello-world"
I have to use this syntax: "url": {{ add .SiteBaseURL "hello-world" }} Strange…