HTML Tags Within JSON (in Python)
I understand its not a desirable circumstance, however if I NEEDED to have some kind of HTML within JSON tags, e.g.: { 'node': { 'list':'
- >Hello World</li><ul>"
}
}
However, with
simplejson
, which is built into Python 2.6 as the json module, it does any escaping you need automatically:>>> import simplejson >>> simplejson.dumps({'node': {'list': '<ul><li class="lists">Hello World</li><ul>'}}) '{"node": {"list": "<ul><li class=\\"lists\\">Hello World</li><ul>"}}'
Solution 2:
You can have arbitrary strings there, including ones which happen to contain HTML tags (the only issue with your example is the inner "
which would confuse any parser).
Post a Comment for "HTML Tags Within JSON (in Python)"