{"id":18023715,"url":"https://github.com/katrix/typed-json","last_synced_at":"2025-04-04T18:25:50.630Z","repository":{"id":208126783,"uuid":"720866047","full_name":"Katrix/typed-json","owner":"Katrix","description":"Typed JSON without decoding it to a case class","archived":false,"fork":false,"pushed_at":"2024-03-21T12:34:08.000Z","size":82,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T03:41:51.820Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Katrix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-19T20:39:06.000Z","updated_at":"2023-11-19T21:09:32.000Z","dependencies_parsed_at":"2023-11-19T22:24:13.271Z","dependency_job_id":"9a98f62d-ad7c-44a8-8786-ecbfb72c9575","html_url":"https://github.com/Katrix/typed-json","commit_stats":null,"previous_names":["katrix/typed-json"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katrix%2Ftyped-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katrix%2Ftyped-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katrix%2Ftyped-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katrix%2Ftyped-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Katrix","download_url":"https://codeload.github.com/Katrix/typed-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247227615,"owners_count":20904728,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-30T07:10:27.829Z","updated_at":"2025-04-04T18:25:50.614Z","avatar_url":"https://github.com/Katrix.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typed-json\n\nScala.js like facades for your JSON data.\n\n## Deps\n\n```scala\nlibraryDependencies += \"net.katsstuff\" %% \"typed-json\" % \"0.1.0\"\n\n// Codegen module\nlibraryDependencies += \"net.katsstuff\" %% \"typed-json-codegen\" % \"0.1.0\"\n```\n\n## Usage\n\ntyped-json provides facades for a number of different things. Here are how to use them. All of these\nhave circe codecs defined for them.\n\n### Objects\n\nMake a class extending `JsonObject`, and a companion object implementing `JsonObjectCompanion`. In\nthe companion object, implement the function `makeRaw`, and any custom factory functions you want.\nFor the factory functions, you can use the function `makeRawFromFields` for circe like syntax.\n\nIn your class, implement your properties. For the accessors, have the implementation\ncall `selectDynamic[A]`. For `withX` functions, call `objWith` for types like `A` or `Option[A]`,\nand call `objWithUndef` for types like `UndefOr[A]` or `JsonOption[A]`.\n\nExample:\n\n```scala\nimport typedjson._\n\nclass Foo(json: Json, startCache: Map[String, Any]) extends JsonObject(json, startCache) {\n\n  def id: Int = selectDynamic[Int](\"id\")\n  def withId(id: Int) = objWith(Foo, \"id\", id)\n\n  def name: JsonOption[String] = selectDynamic[JsonOption[String]](\"name\")\n  def withName(name: JsonOption[String]) = objWithUndef(Foo, \"name\", name)\n\n  def tpe: String = selectDynamic[String](\"type\")\n  def withTpe(tpe: String) = objWith(Foo, \"type\", tpe)\n}\n\nobject Foo extends JsonObjectCompanion[Foo] {\n\n  override def makeRaw(json: Json, cache: Map[String, Any]): Foo = new Foo(json, cache)\n\n  def make(\n    id: Int,\n    name: JsonOption[String],\n    tpe: String\n  ): Foo = makeRawFromFields(\n    \"id\" := id,\n    \"name\" :=? name,\n    \"type\" := tpe\n  )\n}\n\n```\n\n#### Retyping and extensions\n\nIf you want to cast one `JsonObject` to another `JsonObject`, use `retype` instead\nof `asInstanceOf`. This can for example be useful when you have a type `A` that has all the fields\nof another type `B`, plus a few more. When this happen, we call `A` an extension of `B`.\n\nFor extensions, you can use the function `extensionCache` to access a potentially populated cache to\ngive to an extension.\n\n### Enums\n\nMake a sealed case class extending `JsonEnum` with your desired type. Make a companion object and\nextend `JsonEnumCompanion`, passing in your enum type. Next create the named instances for your\nenum. Lastly implement the unknown function to deal with unknown enum values.\n\nExample:\n\n```scala\nimport typedjson._\n\nsealed case class MyEnum(value: String) extends JsonEnum[String]\n\nobject MyEnum extends JsonEnumCompanion[String, MyEnum] {\n  val MyEnumValue1: MyEnum = MyEnum(\"1\")\n  val MyEnumValueFoo: MyEnum = MyEnum(\"foo\")\n\n  override def unknown(s: String): MyEnum = MyEnum(s)\n}\n\n```\n\n### Newtypes\n\nExtend `JsonOpaqueCompanion`, specifying the underlying type.\n\nExample:\n\n```scala\nimport typedjson._\n\ntype Mytype = Mytype.OpaqueType\n\nobject MyType extends JsonOpaqueCompanion[String]\n```\n\n### Video guide\n\n[Impromptu guide filed during Unconference](https://www.youtube.com/watch?v=QND8PxD_MIA)\n\n## Codegen\n\nIf you'd rather not deal with the hassle of setting all of that up, a codegen module is also in the\nwork.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatrix%2Ftyped-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkatrix%2Ftyped-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatrix%2Ftyped-json/lists"}