Skip to content
  • Emmanuele Bassi's avatar
    Add with_default() variant for JsonObject getters · 5b816ff8
    Emmanuele Bassi authored
    When using the typed getters for JsonObject, the existing API will
    automatically fail if the member requested is not present. This is
    generally good practice, because JSON data typically does not have a
    schema, and thus is has to be validated "on the go"; a JSON object
    member that contains `null`, or `0`, or `false`, is indistinguishable
    from a JSON object member that does not exist, so we cannot simply
    return a scalar value and be done with it.
    
    We can provide an escape hatch, though, for the crowd writing parsers
    for JSON data; by using Python as the model, we can add methods that
    take a default value as a parameter, and return it as a fallback value
    if the requested object member does not exist, or if it's set to `null`.
    5b816ff8