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

>Bam! Jo tries to be clever about types and knows null, booleans, strings and numbers.

I'm very skeptical of this. If I put x=001979 in as a value I dont think I want you trying to guess if that's supposed to be an integer or a string.

This sounds like the Norway Problem waiting to happen.



This kind of thing has its place and can be useful, but I think there should be options to enable/disable such magic. Personally I'd lean towards it being opt-in, but I think with the cli it's a lot harder to not have it opt-out. Everythint is a string in the cli, but not so much when it comes to json. That's why I think it makes sense, providing you can disable the magic.


It is reminiscent of a feature in YAML that has bitten people.

But, clearly there is a use-case for producing json with integer, null, and boolean values.


Of course there is, but it should be done explicitly - i.e. treat as a string by default but use -n if it's a number rather than having a guess.


Here is how HTTPie does it:

  x=005  // {"x": "005"}
  X:=005 // {"x": 5}


then use -s :

        jo -- -s opaque_id=001979
        {"opaque_id":"001979"}


jo opaque_id=$(command used in prod that returns digits + letters for three months and everything works just fine and then suddenly at 3am on a Sunday it returns 1979 and breaks everything)

Avoid using this command in prod.


    jo -- -s a=123 -s b=00123 -s c="$(date)"
    {"a":"123","b":"00123","c":"Sat  5 Feb 21:29:08 GMT 2022"}
What's the issue?


The problem is avoiding your surprise ruined Sunday night three months from now is predicated on you not forgetting to put the -s in.

Implicit typing sucks: https://www.destroyallsoftware.com/talks/wat


Agreed, luckily there is a solution ;)


It’s not a solution, it’s a work-around. A solution would be fixing this issue. This allows working around the issue if you remember that it exists.

It’s like saying that it’s fine if an appliance might randomly burn your house, because there’s a button you can press to not burn your house.


I'm sure it'd be a patch of a few lines to make the type specification mandatory on the command line (I would certainly prefer that also), but it comes down to the opinion of the maintainer if that is wanted or not.


It looks like you can specify the value type per property, for those cases where it matters.


Opt-in safety has such a great track record after all.




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

Search: