I do not know how to escape the strings using a “JSON String escape”. The only escape / url_encode available (cf https://shopify.github.io/liquid/) do not implement JSON escaping.
maybe {{ site.posts | jsonify }} would do the whole thing for you? not sure. You’re worried about one of the things containing a { or something and that needs to be escaped right? I have seen examples of people who just do it like you have without escaping, as well as people who make their own plugin to do it properly, but not sure I have seen something like you have that would actually work properly if the data contained stuff that could break it.
So basically, I output a JSON document with 7 sub-arrays of the same length. It’s not super elegant but it does work as I don’t have gazillion posts and can load the entire JSON document in memory in C# and zip the arrays together for Azure Search processing. It works with the limitation of Liquid.
Just to follow up on your idea, a singlet variable (a string, an integer, a number, true/false) can be properly escaped to JSON format with jsonify – double quotes included for strings.
For context, I was trying to add JSON feed to my blog, and each item ended up like:
[{% for post in site.posts %}
{
"title": {{post.title | jsonify}},
"content_html": {{post.content | jsonify}}
},
{% endfor %}]
Note that I did not type the surrounding quotes; jsonify does it for me. Also the trailing comma in the list is not handled – you might want to do something about that