tags:

views:

193

answers:

2

Consider this my json string,

[{"Mat_id" : "2","Mat_Name" : "Steel",
"Measurement" : "mm","Description" : "Steel"}] 

Can i add HTML Tags inside this json string like this,

[{"Mat_id" : "2","Mat_Name" : "Steel",
    "Measurement" : "<bold>mm</bold>","Description" : "Steel"}]
  • Whether this is a valid json string?
  • When Eval('('+ thisstring +')') will raise an issue? If so what is it?

I am doing so because i will pass this json object to a yui datatable which consumes json datasource...

EDIT:

This my resulted json string,

{"Table" : [{"Mat_id" : "2",
"Mat_Name" : "Jully","Measurement" : "<bold>Inches</bold>",
 "Description" : "Gully"},]}

But i didnt get my Measurement column values in bold...

+1  A: 

Yeah.. no problem with that. :)

TiuTalk
+2  A: 

Technically, yes, you can do that... practically, I'd be a bit concerned if there were HTML markup in my data. What else might be in there? Smells like an XSS vulnerability.

Aaronaught
@Aaronaught i didnt get my values of measurement in bold... Are my tags wrong?
Pandiya Chendur
If it's HTML, you should be using `<strong>`.
Anon.
@Anon that worked...
Pandiya Chendur
@Anon y we should use `<strong>` instead of `<bold>`
Pandiya Chendur
The idea is that `<strong>` indicates a general emphasis, rather than a specific style, like `<b>` tags do. You can change what each tag means through the use of CSS, but if you make a `<b>` tag italic, then the tag is lying about what it is. If you make a `<strong>` tag italic, then it still makes sense, semantically. By the way, the reason `<bold>` didn't work is because there is no `<bold>` tag in HTML, only `<b>`.
pib
@pib well said...
Pandiya Chendur
@Pandiya: You weren't too specific about how the tags are getting in there. Normally the conversion from domain objects to JSON is done by some library, so either you're intercepting it or you're passing around unescaped HTML strings in your application. Why don't you just use the YUI API to make the column/cell bold instead? It's easy to skin.
Aaronaught