JSONConverter
public struct JSONConverter
A simple casing converter for dictionary keys, converting either from snake_case
to camelCase
, or from camelCase
to snake_case
.
-
Enum definining the supported JSON conversions
See moreDeclaration
Swift
public enum Conversion
-
Perform the specified casing
conversion
on the keys indictionary
, as governed by theJSONCache.casing
settingDeclaration
Swift
public static func convert(_ conversion: Conversion, dictionary: [String : Any], qualifier: String? = nil) -> [String : Any]
Parameters
conversion
Enum specifying if the conversion is from JSON or to JSON.
dictionary
The dictionary whose keys are to be converted.
qualifier
A string qualifier to prefix onto any reserved words among JSON keys when converting from JSON, or to strip away from reserved words when converting to JSON. Defaults to
nil
if not given. If for instance the qualifier isEntityName
, the JSON keydescription
will be converted toentityNameDescription
. Conversely, the dictionary keyentityNameDescription
will be converted to the JSON keydescription
. The keysomeOtherDescription
, however, will be converted tosome_other_description
(or not converted at all ifJSONCache.casing
is.camelCase
). Ifqualifier
is not given, any string that ends with-Description
will be converted todescription
when converting to JSON. Qualification and dequalification of reserved words is done regardless of whetherJSONCache.casing
specifiessnake_case
orcamelCase
. -
Perform the specified casing
conversion
onstring
, as governed by theJSONCache.casing
settingDeclaration
Swift
public static func convert(_ conversion: Conversion, string: String, qualifier: String? = nil) -> String
Parameters
conversion
Enum specifying if the conversion is from JSON or to JSON.
string
The string to be converted.
qualifier
A string qualifier to prefix onto the string when converting from JSON and the string represents a reserved word, or to strip away from the string when converting to JSON. Defaults to
nil
if not given. If for instance the qualifier isEntityName
, the reserved worddescription
will be converted toentityNameDescription
when converting from JSON. Conversely, the stringentityNameDescription
will be converted todescription
when converting to JSON. The stringsomeOtherDescription
, however, will be converted tosome_other_description
(or not converted at all ifJSONCache.casing
is.camelCase
). Ifqualifier
is not given, any string that ends with-Description
will be converted todescription
when converting to JSON. Qualification and dequalification of reserved words is done regardless of whetherJSONCache.casing
specifiessnake_case
orcamelCase
.