bignerdranch / Freddy

A reusable framework for parsing JSON in Swift.
MIT License
1.09k stars 120 forks source link

Improvements for working with optionals #244

Closed davidahouse closed 7 years ago

davidahouse commented 7 years ago

Fixes #242

This PR addresses two problems:

1) You can't create a JSON from an optional Double, Int, String or Bool. I think a reasonable approach is to turn an optional that is nil into the .null JSON type. This is done via an initializer for example:

let myString: String? = nil
let json = JSON(myString)   // becomes .null

2) When you are serializing a JSON dictionary with values that are .null, it would be nice to include an option that skips the key this null is associated with. Some systems prefer the key is not present in the JSON rather than key = null. Both are valid approaches, hence adding in an options parameter to request the skip key behavior.

rafaelnobrepd commented 7 years ago

Awesome ! 👍