Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm not sure what you mean. json.stringify {2,3,5} == '[2, 3, 5]', which is correct, isn't it? (Strictly, JSON has to always have a dictionary on the outside, but it's fairly standard to allow this.)

We'll keep thinking about this, but I don't think it's sensible to try to encode {11, ["11"]=11} at all. That's neither an array nor a dictionary, and so it doesn't have a natural JSON representation. I'm inclined to make it an error, but right now we try to be generous in attempting to encode.



I had misunderstood the semantics of json.stringify - I thought tables always mapped onto dictionary objects, even if they were arrays. The semantics I suggested is an invertible way of handling that, though the inverse will be odd for JSON arrays whose 0th element is a dictionary object.

Flagging errors in cases with seems to be a good way to handle this kind of problematic input. It's surely better than having applications have nonsensical data if they are given peculiar input.


JSON does not have to have a dictionary at the root. You can have just an array.


Looks like you're right. From http://www.ietf.org/rfc/rfc4627.txt:

"A JSON text is a serialized object or array."

Now I don't know why I thought this wasn't allowed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: