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

[flagged]


> Python, go, rust and other obscure or archaic languages struggle with json. I recommend using a modern language such as js/nodejs, as it is meant for the web - where json is king among formats.

In what ways are the languages you listed obscure or archaic?


I sincerely hope the GP is a troll. No matter, the comment's dead now.


They don't have leftpad.


in js/node is is a valid object

{ hello: 'world' }

in python its not valid

json = { "hello": "world" }

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


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/


I don't understand what you're saying {hello: 'world'} is not valid json and neither Python's nor javascript's json parser from the standard library parse that.


I'm going to be generous and hope this is some really dry humor and not an actual comment


> in js/node is is a valid object > { hello :'world' }

In JSON, that's invalid, because the key must be quoted. Check the spec.


Have you ever used serde-json[0]?

[0] https://github.com/serde-rs/json




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

Search: