You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
ToJSon returns valid syntax for a JavaScript object, but it is not parseable
with many JSON implementations
because it uses syntax that is not within the subset defined by the JSON
standard.
The simplest solution is probably to rename this function or at least document
that it doesn't really return
JSON, but expects to be executed by a full JS interpreter.
For example, the result will not parse with Python 2.6's json package:
>>> d = gviz_api.DataTable(('a', 'string'), ['foo'])
>>> d.ToJSon()
"{cols: [{id:'a',label:'a',type:'string'}],rows: [{c:[{v:'foo'}]}]}"
>>> json.loads(d.ToJSon())
Traceback (most recent call last):
...
ValueError: Expecting property name: line 1 column 1 (char 1)
Some more basic issues are:
- JSON strings must use double-quotes
- JSON keys must be quoted following the string syntax
e.g. {"key": "value"}, not {key: 'value'}
Python's default unicode escaping is also not compatible with JSON strings.
For example, it will use \x hex
escape codes which do happen to work in JavaScript, but JSON only allows \u
4-digit hex escapes, e.g.
Wrong:
>>> json.loads('"\\xfc"')
Traceback (most recent call last):
...
ValueError: Invalid \escape: line 1 column 1 (char 1)
Right:
>>> json.loads('"\\u00fc"')
u'\xfc'
Also, JSON does not define any syntax for Date types, so the "new Date()"
syntax is not supported by most
non-JS-native JSON parsers.
Since this data structure is primarily designed for consumption by the JS viz
API, I don't have a problem with
the syntax remaining as it is, just please don't misrepresent it as "JSON",
which could cause confusion if
people try to parse it with a JSON library.
Original issue reported on code.google.com by m...@matt-good.net on 20 Jul 2009 at 10:05
The text was updated successfully, but these errors were encountered:
I ran into this issue as I tried to use it with jQuery.getJSON. A bad
combination since the function fails silently if the JSON isn't valid. Please
fix this or at least rename the method.
Original comment by martin.thurau on 25 Sep 2010 at 11:21
I ran into this issue as well. There is a stackoverflow question which would
be useful if to keep up to date:
http://stackoverflow.com/questions/6007381/invalid-json-string-in-google-visuali
zation-api-example
Original comment by dgoris...@gmail.com on 19 May 2011 at 10:48
Original issue reported on code.google.com by
m...@matt-good.net
on 20 Jul 2009 at 10:05The text was updated successfully, but these errors were encountered: