matthewcheok / JSONCodable

Hassle-free JSON encoding and decoding in Swift
MIT License
602 stars 66 forks source link

Working with keys that have '.' (dot) in it #64

Open vytis opened 7 years ago

vytis commented 7 years ago

It seems that after pull request https://github.com/matthewcheok/JSONCodable/pull/53 JSONCodable got functionality for encoding/decoding nested types (https://github.com/matthewcheok/JSONCodable/pull/53/commits/9782c0fc77679c92fcd5d9a8a082305db121e2d1). However the problem we are having is that our API JSON responses have some keys with . in them. This makes it impossible to encode (and probably parse) the JSONs using the library.

For example this JSON is not parseable correctly with the lib:

{
   "one.key" = "value"
}

Is there a way to fallback to a more low-level approach avoiding the key.components(separatedBy: ".") part in each of func encode(_ value: key:) overload?

Nadohs commented 7 years ago

This seems to be more of an edge case while what we optimized for seemed to be more common and expected. Your welcome to submit a PR for this functionality as perhaps an OptionSet on the JSONEncoder initializer, otherwise we will keep this in mind for potential implementation in the future.