javascript - Is it a good idea to use strings for all data types in JSON? -


so example, better practice when designing json returned server :

approach1 : returning values correct types :

{     "id": 1,     "name": "a green door",     "price": 12.50,     "tags": ["home", "green"] } 

or

approach2 : wrapping values in double-quotes follows :

{     "id": "1",     "name": "a green door",     "price": "12.50",     "tags": ["home", "green"] } 

which approach better? pros , cons of each approach? there tradeoffs?

it's best use quotes actual strings, , not other types integers.

by storing string app parses json , expects int gets string instead throw exception. can have impact on performance strings use more memory other types.

depending on situation off course write or find parser takes care of type conversion, it's easier use quotes intended.

so unless have feed json existing app expects every type stored string don't see reason use quotes types.


Comments