You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reading the docs for algolia, I noticed that you encourage at least Swift and C# users to load JSON data as dynamic values (e.g. Dictionary and JObject). Since this repo is about awesomeness, I thought you might be able to benefit from quicktype.
quicktype can infer types from JSON data and provide types and marshaling code in a variety of languages. For example, here's how to quicktype your airports.json sample dataset:
typealiasAirports=[Airport]structAirport:Codable{letname,city,country,iataCode:Stringletgeoloc:GeolocletlinksCount:IntletobjectID:StringenumCodingKeys:String,CodingKey{case name, city, country
case iataCode ="iata_code"case geoloc ="_geoloc"case linksCount ="links_count"case objectID
}}structGeoloc:Codable{letlat,lng:Double}extensionArraywhere Element ==Airports.Element{init(data:Data)throws{self=tryJSONDecoder().decode(Airports.self, from: data)}init(_ json:String, using encoding:String.Encoding=.utf8)throws{
guard let data = json.data(using: encoding)else{throwNSError(domain:"JSONDecoding", code:0, userInfo:nil)}tryself.init(data: data)}func jsonData()throws->Data{returntryJSONEncoder().encode(self)}func jsonString(encoding:String.Encoding=.utf8)throws->String?{returnString(data:tryself.jsonData(), encoding: encoding)}}
Then you can easily go from JSON with Airports(jsonString) and to JSON with airports.jsonString(). With native support for Codable in the algolia Swift SDK, you could make using algolia even nicer and more strongly typed without the need for the user to marshal strings or dynamic values.
quicktype would allow your C#, Swift, Objective-C, Java, Go, C++, etc. users use algolia type-safely with little effort. Not sure if this is useful in general, but I thought I'd draw your attention to this capability just in case!
The text was updated successfully, but these errors were encountered:
Reading the docs for algolia, I noticed that you encourage at least Swift and C# users to load JSON data as dynamic values (e.g.
Dictionary
andJObject
). Since this repo is about awesomeness, I thought you might be able to benefit from quicktype.quicktype can infer types from JSON data and provide types and marshaling code in a variety of languages. For example, here's how to quicktype your
airports.json
sample dataset:This is the generated code:
Then you can easily go from JSON with
Airports(jsonString)
and to JSON withairports.jsonString()
. With native support forCodable
in the algolia Swift SDK, you could make using algolia even nicer and more strongly typed without the need for the user to marshal strings or dynamic values.quicktype would allow your C#, Swift, Objective-C, Java, Go, C++, etc. users use algolia type-safely with little effort. Not sure if this is useful in general, but I thought I'd draw your attention to this capability just in case!
The text was updated successfully, but these errors were encountered: