3

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>");

1 Answer 1

11

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Can you please tell me how to use replace all or replace no of strings in one statement?
The g means global there, so it would replace all occurrences. I am not sure what you mean with "replace no of strings"? Do you mean stop after a certain number of replacements?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.