Help to deal with json and string formatting

My theme has a search bar involving json and some javascript.
My titles and sections’ titles often have ponctuations in them. While the menus can render them well, and I can plainify markup, but I don’t know how to automatically escape ponctuation in the json part then unescape it to display it correctly.
I have no experience whatsoever with json, can you help me what is basically improving on this theme ? It probably comes down to a few words.

---
Title : "Man's regeneration"

Error message:

 MINIFY: failed to transform "en.search-data.json" (application/json): JSON parse error: unexpected character 'M' on line 6 and column 16     6:     "section": Man’s demise,                       ^ 

search-data.json

[
{{- $pages := where .Site.Pages "Kind" "in" (slice "page" "section") -}}
{{- $pages = where $pages "Params.booksearchexclude" "!=" true -}}

{{ range $index, $page := $pages }}
{{ if gt $index 0}},{{end}} {
    "id": {{ $index }},
    "href": "{{ $page.RelPermalink }}",
    "title": {{ (partial "docs/title" $page)|plainify|jsonify }},
    "section": {{ markdownify (partial "docs/title" $page.Parent) }},
    "content": {{ $page.Plain | jsonify }}
}
{{- end -}}
]

Here’s the sample

Thanks !

1 Like

The error message is not about punctuation. And I don’t see the relationship between front matter and JSON. Unless the single line you posted is supposed to be JSON?

It would really help others to help you if you made an effort to provide more context. A single line of code and an error message is anything but.

For example, it would help to see the output of search-data,json.

It’s complicated to explain and easier to see !
So this is the search bar:


This is how “Man’s regeneration” (the section’s title) and “Cooking, the original sin” appear in the results:

What provides the information about titles and sections, are those json files, search-data.json
in particular or so I think. The problem is that I want the markup from my titles to be rendered in the search result, and they are not, instead I have things like Cooking: the <Em>Original Sin</em>. I don’t know how to get it to render to html.

What if you remove plainify?

1 Like

Ok, | htmlUnescape| plainify| jsonify does the trick. Unescaping and planifying everything.
But I actually wanted to render the markup on the screen, not just remove it.