{"id":32183878,"url":"https://github.com/furkan3ayraktar/json-schema","last_synced_at":"2026-03-17T22:32:31.715Z","repository":{"id":62431816,"uuid":"137693296","full_name":"furkan3ayraktar/json-schema","owner":"furkan3ayraktar","description":"A library to generate JSON schemas from Clojure specs.","archived":false,"fork":false,"pushed_at":"2018-06-17T23:33:11.000Z","size":11,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2026-02-25T19:38:54.633Z","etag":null,"topics":["clojure-spec","json-schema"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/furkan3ayraktar.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}},"created_at":"2018-06-17T23:08:51.000Z","updated_at":"2024-06-15T11:15:18.000Z","dependencies_parsed_at":"2022-11-01T20:46:43.529Z","dependency_job_id":null,"html_url":"https://github.com/furkan3ayraktar/json-schema","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/furkan3ayraktar/json-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/furkan3ayraktar%2Fjson-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/furkan3ayraktar%2Fjson-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/furkan3ayraktar%2Fjson-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/furkan3ayraktar%2Fjson-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/furkan3ayraktar","download_url":"https://codeload.github.com/furkan3ayraktar/json-schema/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/furkan3ayraktar%2Fjson-schema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29977966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T16:35:47.903Z","status":"ssl_error","status_checked_at":"2026-03-01T16:35:44.899Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["clojure-spec","json-schema"],"created_at":"2025-10-21T23:07:53.423Z","updated_at":"2026-03-17T22:32:31.706Z","avatar_url":"https://github.com/furkan3ayraktar.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-schema\n\nA library to generate JSON schemas from Clojure specs.\nIt provides utility functions to convert both Clojure specs\nand [spec-tools](https://github.com/metosin/spec-tools) specs\ninto [JSON schema](http://json-schema.org).\n\n[![Clojars Project](https://img.shields.io/clojars/v/com.furkanbayraktar/json-schema.svg)](https://clojars.org/com.furkanbayraktar/json-schema)\n[![GitHub license](https://img.shields.io/github/license/furkan3ayraktar/json-schema.svg)](LICENSE)\n[![Circle CI](https://circleci.com/gh/furkan3ayraktar/json-schema/tree/master.svg?style=shield)](https://circleci.com/gh/furkan3ayraktar/json-schema/tree/master)\n\n## Installation\n\nTo include `json-schema`, add the following to your\n`:dependencies`:\n\n    [com.furkanbayraktar/json-schema \"0.1.0\"]\n\n## Usage\n\njson-schema provides a function called `spit-schemas!` to write\nJSON schemas to individual files. By default, it uses `schemas`\nfolder in your project root. Here is a sample use case:\n\n```clojure\n(ns json-schema-test.core\n  (:require [clojure.spec.alpha :as s]\n            [clojure.string :as str]\n            [com.furkanbayraktar.json-schema.core :as js]\n            [spec-tools.core :as st]\n            [spec-tools.data-spec :as ds]))\n\n;; Clojure specs\n\n(s/def :test/field-1 (s/and string? #(not (str/blank? %))))\n(s/def :test/field-2 pos-int?)\n(s/def :test/field-3 boolean?)\n\n(s/def :test/test-spec (s/keys :req-un [:test/field-1 :test/field-2]\n                               :opt-un [:test/field-3]))\n\n;; spec-tools specs\n\n(def my-integer? (assoc (st/spec integer?)\n                   :description \"It's an int\"\n                   :name :test/my-integer))\n\n(def not-blank-string-regex #\"^.*\\S.*$\")\n\n(def not-blank-string?\n  (st/spec {:spec :test/field-1\n            :type :string\n            :description \"A non blank string checked by clojure.string/blank?\"\n            :json-schema/pattern (str not-blank-string-regex)}))\n\n;; spec-tools data spec\n\n;; spec-tools data spec does not add :name to Spec record, so it needs to\n;; be added manually.\n(def test-data-spec\n  (assoc\n    (ds/spec {:name :test/data-spec\n              :spec {:id my-integer?\n                     :name :test/field-1\n                     :description not-blank-string?\n                     :birthday (s/int-in 1900 2018)}})\n    :name :test/data-spec))\n\n;; Function to be called through leiningen (or anywhere else) when needed\n(defn generate-schemas! []\n  (js/spit-schemas! [:test/test-spec my-integer? test-data-spec]))\n```\n\nOnce you have a function like `generate-schemas!` that calls spit-schemas!,\nyou can define an alias in your `project.clj` file in order to generate\nschema files on your continuous integration pipeline or any time you need\noutside of the project. You can learn more about creating aliases on\n[leiningen documentation](https://github.com/technomancy/leiningen/blob/master/doc/PLUGINS.md#not-writing-a-plugin-无为).\n\n```clojure\n(defproject json-schema-test \"0.1.0-SNAPSHOT\"\n  :description \"Test project for json-schema\"\n  :dependencies [[com.furkanbayraktar/json-schema \"0.1.0\"]\n                 [metosin/spec-tools \"0.7.0\"]\n                 [org.clojure/clojure \"1.9.0\"]]\n\n  ;; Alias that calls generate-schemas! function to generate\n  ;; JSON schemas from your specs!\n\n  :aliases {\"generate-schemas\" [\"run\" \"-m\" \"json-schema-test.core/generate-schemas!\"]})\n```\n\nThe alias named `generate-schemas` will let you run:\n\n    $ lein generate-schemas\n\non your command line. It will generate an output like this:\n\n```\n$ lein generate-schemas\n\nJSON Schema: Deleting old schemas.\nJSON Schema: Deleting /Users/furkan/test-json-schema/schemas/TestSpec.json\nJSON Schema: Deleting /Users/furkan/test-json-schema/schemas/MyInteger.json\nJSON Schema: Creating /Users/furkan/test-json-schema/schemas/DataSpec.json\nJSON Schema: Creating schema files.\nJSON Schema: Creating /Users/furkan/test-json-schema/schemas/TestSpec.json\nJSON Schema: Creating /Users/furkan/test-json-schema/schemas/MyInteger.json\nJSON Schema: Creating /Users/furkan/test-json-schema/schemas/DataSpec.json\nJSON Schema: Done!\n```\n\nIf you open `DataSpec.json` file under `schemas` folder, you will see:\n\n```json\n{\n  \"type\" : \"object\",\n  \"properties\" : {\n    \"id\" : {\n      \"type\" : \"integer\",\n      \"description\" : \"It's an int\",\n      \"title\" : \"test/my-integer\"\n    },\n    \"name\" : {\n      \"type\" : \"string\"\n    },\n    \"description\" : {\n      \"type\" : \"string\",\n      \"description\" : \"A non blank string checked by clojure.string/blank?\",\n      \"pattern\" : \"^.*\\\\S.*$\"\n    },\n    \"birthday\" : {\n      \"allOf\" : [ {\n        \"type\" : \"integer\",\n        \"format\" : \"int64\"\n      }, {\n        \"minimum\" : 1900,\n        \"maximum\" : 2018\n      } ]\n    }\n  },\n  \"required\" : [ \"id\", \"name\", \"description\", \"birthday\" ],\n  \"title\" : \"test/data-spec\"\n}\n```\n\nYou can find different options you can pass to `spit-schemas!` function\nin the next section or in the documentation of function.\n\njson-schema contains other utility functions like `spec-\u003ejson-schema` and\n`spec-\u003ejson-schema-map`. `spec-\u003ejson-schema` returns a JSON schema string\nfor given spec. Similarly, `spec-\u003ejson-schema-map` returns a Clojure map\nof the JSON Schema, if you prefer to convert JSON string later on.\n\n```clojure\n(spec-\u003ejson-schema :test/test-spec)\n```\n\nevaluates to:\n\n```clojure\n=\u003e\n\"{\n   \\\"type\\\" : \\\"object\\\",\n   \\\"properties\\\" : {\n     \\\"field-1\\\" : {\n       \\\"type\\\" : \\\"string\\\"\n     },\n     \\\"field-2\\\" : {\n       \\\"type\\\" : \\\"integer\\\",\n       \\\"format\\\" : \\\"int64\\\",\n       \\\"minimum\\\" : 1\n     },\n     \\\"field-3\\\" : {\n       \\\"type\\\" : \\\"boolean\\\"\n     }\n   },\n   \\\"required\\\" : [ \\\"field-1\\\", \\\"field-2\\\" ]\n }\"\n```\n\nSimilarly,\n\n```clojure\n(spec-\u003ejson-schema-map :test/test-spec)\n```\n\nevaluates to:\n\n```clojure\n=\u003e\n{:type \"object\",\n :properties {\"field-1\" {:type \"string\"},\n              \"field-2\" {:type \"integer\", :format \"int64\", :minimum 1},\n              \"field-3\" {:type \"boolean\"}},\n :required [\"field-1\" \"field-2\"]}\n```\n\n## Options\n\n```clojure\n(defn spit-schemas!\n  ([specs {:keys [delete-old-schemas?             ; If false, does not delete old schema files before creating new.\n                  output-path                     ; Defines the output folder for generated schema files.\n                  additional-props?               ; If false, adds adds additionalProperties field with false value to schema.\n                  convert-name?                   ; If false, keeps spec name as file name, otherwise converts it to PascalCase\n                  pretty?]                        ; If false, skips prettifying JSON string.\n           :or   {delete-old-schemas? true\n                  output-path         \"schemas\"\n                  additional-props?   true\n                  convert-name?       true\n                  pretty?             true}}]\n\n  ; ...\n```\n\n```clojure\n(defn spec-\u003ejson-schema\n  ([spec\n    additional-props? ; If false, adds additionalProperties field with false value to schema.\n    pretty?]          ; If false, skips prettifying JSON string.\n\n  ; ...\n\n  ([spec]\n   (spec-\u003ejson-schema spec true true)))\n```\n\n```clojure\n(defn spec-\u003ejson-schema-map\n  ([spec\n    additional-props?] ; If false, adds additionalProperties field with false value to schema.\n\n  ; ...\n\n  ([spec]\n   (spec-\u003ejson-schema-map spec true)))\n```\n\nReference to [additionalProperties](http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.6)\ncan be found in the link.\n\nReference to [Pascal Case](https://en.wikipedia.org/wiki/Camel_case) can be found in the link.\n\n## License\n\nCopyright © 2018 Furkan Bayraktar\n\nDistributed under the Eclipse Public License, the same as Clojure.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffurkan3ayraktar%2Fjson-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffurkan3ayraktar%2Fjson-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffurkan3ayraktar%2Fjson-schema/lists"}