String replace values recursively in json

javascript, jquery, json

Solution

This converts the JSON into string

JSON.stringify(json).replace(/¬/g, "<span class='math'>x</span>")

and then you could convert it back to JSON

JSON.parse(json)

Problem

I have a json object such as: ``` var json = { "title": "Math Symbols: ¬", "sections": [ "The ¬ symbol", "¬ and y" ] }; ``` I need to replace all instances of the "¬" character with something that looks like the Mathematical symbol for x: sample. Side note: I can't use that actual symbol (html entity `&#119909;`) because the Arial font i'm using doesn't support it. So I was planning on replacing "¬" with `<span class="math">x</span>` and styling the math class with Times New Roman & italic. I can't change the Arial Font, and I don't need any other Math symbols - MathML support or the like isn't necessary. Something like this would be ideal: ``` json = json.replace("¬", "<span class='math'>x</span>"); ```

Original source