{"id":19758080,"url":"https://github.com/paurkedal/ocaml-kojson","last_synced_at":"2026-04-16T17:41:30.458Z","repository":{"id":136457581,"uuid":"14444920","full_name":"paurkedal/ocaml-kojson","owner":"paurkedal","description":"Combinators for matching JSON","archived":false,"fork":false,"pushed_at":"2023-01-07T09:23:48.000Z","size":53,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-28T09:23:46.295Z","etag":null,"topics":["json","ocaml","parser-combinators","yojson"],"latest_commit_sha":null,"homepage":"http://paurkedal.github.io/ocaml-kojson/","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paurkedal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"COPYING","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":"2013-11-16T09:45:17.000Z","updated_at":"2022-01-27T22:17:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"c16d5de6-4421-4fbc-b617-da58d7444dc6","html_url":"https://github.com/paurkedal/ocaml-kojson","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/paurkedal/ocaml-kojson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paurkedal%2Focaml-kojson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paurkedal%2Focaml-kojson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paurkedal%2Focaml-kojson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paurkedal%2Focaml-kojson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paurkedal","download_url":"https://codeload.github.com/paurkedal/ocaml-kojson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paurkedal%2Focaml-kojson/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268696896,"owners_count":24292383,"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","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["json","ocaml","parser-combinators","yojson"],"created_at":"2024-11-12T03:22:52.286Z","updated_at":"2026-04-16T17:41:30.406Z","avatar_url":"https://github.com/paurkedal.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kojson - JSON Parser Combinators\n\n## Synopsis\n\nKojson provides combinators to construct functions to match JSON values in a\nconvenient and asymptotically efficient way.  The patterns take as input the\npolymorphic variant `Yojson.Basic.json` wrapped with location information\nfor precise error reporting.  The library provides two top-level modules:\n\n  * `Kojson` - Contains general definitions.\n  * `Kojson_pattern` - Contains the combinators. You should open this where\n    needed.  It provides a `K` substructure to match trees, a `Ka`\n    substructure to match associations, and some operators.\n\nFor details, see [the API reference](http://paurkedal.github.io/ocaml-kojson/).\n\n### Example\n\nThe following decodes a list of objects containing two mandatory and one\noptional attributes:\n\n```OCaml\nopen Kojson_pattern\nopen Unprime\nopen Unprime_option\n\nlet decode_log =\n  K.list begin\n    K.assoc begin\n      \"time\"^: K.int %\u003e fun time -\u003e\n      \"facility\"^?: Option.map K.string %\u003e fun facility_opt -\u003e\n      \"message\"^: K.string %\u003e fun message -\u003e\n      Ka.stop (time, facility_opt, message)\n    end\n  end\n```\n\nThe input to this is constructed with `Kojson.jin_of_json` and it will throw\na `Kojson.Mismatch` exception if the pattern does not match.  E.g.  loading\nthe JSON data from a file:\n\n```OCaml\nlet handle_error fp msg = failwith (\"Cannot load \"^fp^\": \"^msg^\"\\n\")\n\nlet load_log_file fp =\n  try decode_log (Kojson.jin_of_json (Yojson.Basic.from_file fp)) with\n  | Yojson.Json_error msg -\u003e handle_error fp msg\n  | Kojson.Mismatch (path, expect) -\u003e\n    handle_error fp (Kojson.string_of_mismatch (path, expect))\n```\n\nIf the file does not contain valid JSON data, then Yojson will point to the\nfile and line number.  If the pattern does not match, then Kojson will\nindicate the logical path of the mismatch using labels and indices.\n\n## Installation\n\nThe package is available though the [author's OPAM repository][1]:\n\n    opam repo add paurkedal https://github.com/paurkedal/opam-repo-paurkedal.git\n    opam install kojson\n\nAlternatively use `topkg/pkg.ml` (or `opam pin`) from a Git checkout or tar\nextraction.\n\n### Dependencies\n\n* [Prime](https://github.com/paurkedal/ocaml-prime)\n* [Topkg](http://erratique.ch/software/topkg) (build only)\n* [Yojson](http://mjambon.com/yojson.html)\n\n### See Also\n\n* [atdgen](https://github.com/mjambon/atdgen)\n* [deriving-yojson](https://github.com/hhugo/deriving-yojson)\n* [jsont](http://erratique.ch/software/jsont)\n* [piqi](http://piqi.org/)\n* [ppx_deriving_yojson](https://github.com/whitequark/ppx_deriving_yojson)\n\n[1]: https://github.com/paurkedal/opam-repo-paurkedal\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaurkedal%2Focaml-kojson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaurkedal%2Focaml-kojson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaurkedal%2Focaml-kojson/lists"}