Hacker News new | past | comments | ask | show | jobs | submit login

None of those mean Python is "obscure or archaic" or "unfit for json" etc.

Regarding what is a valid object, it's about syntax. Python has a different syntax than JS. That doesn't mean Python is worse because JS has {hello: 'world'}.

In fact that's an inconsistency of JS that only holds for _some_ keys (basically, valid identifiers): if the key has a space or a dash or something, you need to quote it: {'hello-1': 'world'}. So Python is more consistent in having only one style of map literal.

>in python you also can't do json.hello like in js, it would be json['hello']

Again, irrelevant. Python has a different syntax. Python also has tons of stuff you can't do in JS. Operator overloading for example, in python myObj + myOtherObj is a valid user defined operation. None of this means JS or Python is superior.

Ans none of this has anything to do with JSON.

If you mean that JSON seems to be a better fit for JS syntax, that's because it was designed to be closer to JS syntax. That said, it's not JS syntax. {foo: "bar"} is valid JS but not JSON. JSON also doesn't accept classes, closures, and tons of other things that can go in a JS object.




Plus, if you really want it Python has tons of hooks to make json.load return whatever sort of struct you want.


Or you can let json.load do its thing and use a nice module like json-syntax[1] to convert it to well typed values and back. (Yup, plugging my library.)

[1]: https://pypi.org/project/json-syntax/




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: