News for hackers. Stuff that matters.
Re:Debunking the myths about parsing JSON in Swift by seivan on Thursday February 18, 2016 @09:35AM (#11125968)
Yes! Someone finally said it. The worst are the operators. You don't need these libraries and their lack of tests.

Noticed this might be an ad about a book... Parsing JSON in Swift. The bubble is real. What developer would buy this? What's next, a book about NSURLSession?

Re:Debunking the myths about parsing JSON in Swift by jtbrown on Thursday February 18, 2016 @10:07AM (#11126222)
Wait... who told you I was writing that book? Just wait till you read next week's article: "Debunking the myths about networking in Swift"
Re:Debunking the myths about parsing JSON in Swift by mpweiher on Thursday February 18, 2016 @11:14AM (#11126764)
And here's your regularly scheduled announcement that the actual JSON parsing is done by the library call NSJSONSerialization.JSONObjectWithData(...) in line 3 of the code.

The rest is just getting the parsed data out of already parsed nested dictionaries and arrays in a way that makes the type checker happy. Calling that "parsing" is probably the biggest myth of them all (though agreed about all the other myths).

Re:Debunking the myths about parsing JSON in Swift by efaref on Thursday February 18, 2016 @11:45AM (#11127025)
True. Although the Android JsonReader class does force you to write your own parser (it is itself merely a lexer). This is really inelegant.

What I'd really like is a way to write my POD types as normal:

  class Foo {
    int bar;
    String baz;
    ArrayList<String> blah;
    ArrayList<Xyz> xyzs;
  }

  class Xyz
  {
    String name;
    int value;
  }
And then just write this to parse it all.

  ...
  Parser<Foo> p = new Parser<Foo>();
  Foo f;
  try {
    f = gp.parse(input);
  } catch (JsonParseException e) {
    ...
  }
I'd be willing to accept having to annotate some of the fields, (but other than that, this should be possible to do).
Re:Debunking the myths about parsing JSON in Swift by hxucaa on Thursday February 18, 2016 @10:32AM (#11126432)
Swiftz (https://github.com/typelift/Swiftz) offers well tested implementation of operator definitions and constructs from functional language. It takes inspiration from Scalaz and Haskell. If I were to write a library using wacky operators, I'd at least use well defined and maintained definitions.
Re:Debunking the myths about parsing JSON in Swift by wrong_variable on Thursday February 18, 2016 @10:54AM (#11126603)
Why is parsing JSON a problem in 2016 ?
Re:Debunking the myths about parsing JSON in Swift by krapp on Thursday February 18, 2016 @10:57AM (#11126627)
It's not if you use a language that comes with its own JSON parser.

I don't know why anyone would bother writing their own, though.

Re:Debunking the myths about parsing JSON in Swift by wrong_variable on Thursday February 18, 2016 @11:04AM (#11126683)
Does Swift not have its own JSON parser ?

(IMA non-swift programmer)

Re:Debunking the myths about parsing JSON in Swift by tarentel on Thursday February 18, 2016 @11:26AM (#11126868)
The Swift JSON parser is written in Objective-C. So kind of.
Re:Debunking the myths about parsing JSON in Swift by tomguthrie on Thursday February 18, 2016 @11:40AM (#11126985)
Beginnings of a Swift one in the corelibs version of Foundation: https://github.com/apple/swift-corelibs-foundation/blob/mast...
Re:Debunking the myths about parsing JSON in Swift by wrong_variable on Thursday February 18, 2016 @12:40PM (#11127595)
How sad. Apple has 80 billion dollar in cash - and are unable to pay someone to write a standard JSON parser - for a language they want other developer to adopt. Do they expect unpaid developers to make one for them ?
Re:Debunking the myths about parsing JSON in Swift by seanalltogether on Thursday February 18, 2016 @11:48AM (#11127062)
doesn't look like it's protecting against nsnull values
Re:Debunking the myths about parsing JSON in Swift by jtbrown on Thursday February 18, 2016 @01:36PM (#11128075)
If you're talking about either the bad (pyramid of doom) code in Myth #1 - or the good code there, then it is indeed protecting against null values in the JSON. When you try to cast with `as? String`, it returns nil when there's a null value in the JSON and the code in the `if` block is skipped (and the `else` block is executed if one exists).
Re:Debunking the myths about parsing JSON in Swift by seanalltogether on Thursday February 18, 2016 @05:16PM (#11129770)
The point is that neither of them are good. Nulls should be expected in json objects, so why write the parsing inside a conditional that will fail when one is encountered?