HNNewShowAskJobs
Built with Tanstack Start
Codables – Swift-inspired, declarative JSON serialization(github.com)
18 points by pie6k 11 days ago | 7 comments
  • jb19912 days ago

    Since it’s your own project, would probably benefit from the “Show HN” title.

  • happytoexplaina day ago

    Capturing types in the JSON means you need this tool at both ends. E.g. you couldn't use this to serialize data to send to a typical web API. Is there no way to use TS to declare the type at decode time, like you would in Swift and other strongly typed languages? I'm not super familiar with TS.

  • pie6k11 days ago

    Hey! Why yet another JSON serialization library? We already have SuperJSON, right?

    Yes. And SuperJSON is great; I use it a lot. However, things got tricky for me when I had really complex data types, covered with many model classes, often deeply nested and referencing each other, where I needed to serialize it all from/to JSON and save it on the disk. I had to essentially maintain two formats of my data - "serializable data" and TypeScript classes matching this data. It was quite a pain.

    I've tried to solve it with modern decorators, making the entire process more declarative and having way less boilerplate.

    Happy to hear your feedback!

    Interactive playground - https://codableslib.com/playground Github: https://github.com/pie6k/codables

  • boxed2 days ago

    "for typescript" in the title would have been a good idea

    • trymas2 days ago |parent

      Also - what's so "Swift-inspired"? There's not a single mention of Swift in README.

      • secretsatana day ago |parent

        It’s based on Swift’s codable protocol: https://developer.apple.com/documentation/swift/codable

        • boxeda day ago |parent

          Very loosely. Swift Codable doesn't require you to annotate every field for example.