zadr / j2s Goto Github PK
View Code? Open in Web Editor NEWA macOS app to convert JSON to Swift structs
License: Other
A macOS app to convert JSON to Swift structs
License: Other
And/or we need to scan our tree of structs to see if anything has a custom strategy to handle.
For example: In the demo we show off, the given JSONDecoder()
needs an iso8601 date strategy because Nested
has an iso8601 date to parse.
for the same reason as identifying locale strings and turning them into Locale
objects.
j2s
String depluralization is currently naive and unhelpfully does the wrong thing for a lot of plural words. It would be great to do better.
it might be useful to emit a dictionary view of a struct, so we can convert back to a JSON object if needed (say, for POST
ing changes).
This might be a task better left for external codegen (say, from Sourcery
), but it's closely related to the work that j2s
already does, so it might get a slide anyway (in the same way that j2s
emits Hashable
and Equatable
implementations already anyway).
This may also be a better fit in j2s
than another tool because we'll still have the context for what format data came in from (e.g.: was a Date
an epoch time? Rails' Time.now
? ISO 8601? etc)
j2s
currently only identifies date strings in the format of eee MMM dd HH:mm:ss Z yyyy
(or: Sat Dec 31 04:27:14 +0000 2016
) which is given by Rails and Time.now
, but it would be nice to recognize more common date formats (iso8601, rfc822, epoch, etc)
app will freeze if input json like this
{
"pages": [
{
"cid": 19965680,
"page": 1,
"from": "vupload",
"part": "NEW GAME!! 01",
"duration": 1421,
"vid": "",
"weblink": "",
"metas": [
{
"quality": 16,
"format": "",
"size": 97693
}
]
}
]
}
this one requires a bit more thought, since macOS and iOS have different color constructs
BCP 47 defines Tags for Identifying Languages.
Given the following JSON:
{
"language": "en",
"foo": true
}
j2s
will currently output the following Swift code:
public struct Root {
let foo: Bool
let language: String
init?(_ dictionary: [String: Any]) {
if let foo = dictionary["foo"] as? Bool {
self.foo = foo
} else {
return nil
}
if let language = dictionary["language"] as? String {
self.language = language
} else {
return nil
}
}
}
but it might be useful if could identify BCP 47 identifiers and instead output code using Locale
s, such as:
public struct Root {
let foo: Bool
let language: String
init?(_ dictionary: [String: Any]) {
if let foo = dictionary["foo"] as? Bool {
self.foo = foo
} else {
return nil
}
if let language = dictionary["language"] as? String {
Locale(localeIdentifier: language)
} else {
return nil
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.