### Install via Homebrew Source: https://github.com/sourcemeta/jsonschema/blob/main/README.markdown Use Homebrew to install the JSON Schema CLI. ```sh brew install sourcemeta/apps/jsonschema ``` -------------------------------- ### Install sourcemeta_library Source: https://github.com/sourcemeta/jsonschema/blob/main/vendor/core/src/lang/preprocessor/CMakeLists.txt Conditionally installs the sourcemeta library for the preprocessor module. The installation is triggered by the SOURCEMETA_CORE_INSTALL variable. ```cmake if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME preprocessor) endif() ``` -------------------------------- ### Install via Snap Source: https://github.com/sourcemeta/jsonschema/blob/main/README.markdown Install the JSON Schema CLI using snap. Note Snap confinement limitations. ```sh sudo snap install jsonschema ``` -------------------------------- ### Install via Shell Script Source: https://github.com/sourcemeta/jsonschema/blob/main/README.markdown Download and execute a POSIX shell script to install pre-built binaries. ```sh curl -fsSL https://raw.githubusercontent.com/sourcemeta/jsonschema/main/install -H 'Cache-Control: no-cache, no-store, must-revalidate' | /bin/sh ``` -------------------------------- ### Install via mise Source: https://github.com/sourcemeta/jsonschema/blob/main/README.markdown Use mise to manage and install the JSON Schema CLI. ```sh mise use jsonschema ``` -------------------------------- ### Install with verbose output Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/install.markdown Provides detailed output during the installation process, which can be helpful for debugging or understanding the steps involved. ```sh jsonschema install --verbose ``` -------------------------------- ### Install @sourcemeta/blaze Source: https://github.com/sourcemeta/jsonschema/blob/main/vendor/blaze/ports/javascript/README.md Install the @sourcemeta/blaze package using npm. ```sh npm install --save @sourcemeta/blaze ``` -------------------------------- ### Install via PyPI Source: https://github.com/sourcemeta/jsonschema/blob/main/README.markdown Install the JSON Schema CLI using pip from PyPI. ```sh pip install sourcemeta-jsonschema ``` -------------------------------- ### Install via npm Source: https://github.com/sourcemeta/jsonschema/blob/main/README.markdown Install the JSON Schema CLI globally using npm. ```sh npm install --global @sourcemeta/jsonschema ``` -------------------------------- ### Install with configuration file Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/install.markdown Declares dependencies in a `jsonschema.json` file and then runs the install command. This method is useful for managing multiple dependencies and their mappings to local paths. ```json { "dependencies": { "https://schemas.sourcemeta.com/sourcemeta/std/v0/jsonrpc/v2.0/response": "./vendor/response.json" } } ``` -------------------------------- ### Install via gah Source: https://github.com/sourcemeta/jsonschema/blob/main/README.markdown Install the JSON Schema CLI using the gah package manager. Ensure ~/.local/bin is in your PATH. ```sh gah install jsonschema ``` -------------------------------- ### Install Project Rules Source: https://github.com/sourcemeta/jsonschema/blob/main/vendor/core/vendor/googletest/googlemock/CMakeLists.txt Defines the installation rules for the Google Mock project, including the gmock and gmock_main libraries. This command is used to package the built libraries for deployment. ```cmake install_project(gmock gmock_main) ``` -------------------------------- ### Build from Source Source: https://github.com/sourcemeta/jsonschema/blob/main/README.markdown Clone the repository, configure with CMake, build, and install the JSON Schema CLI. ```sh git clone https://github.com/sourcemeta/jsonschema cd jsonschema cmake -S . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release cmake --build ./build --config Release --parallel 4 cmake --install ./build --prefix \ --config Release --verbose --component sourcemeta_jsonschema ``` -------------------------------- ### Example Schema for Inspection Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/inspect.markdown This example schema demonstrates a local reference that can be analyzed using the `inspect` command. ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://example.com", "$ref": "#/$defs/string", "$defs": { "string": { "type": "string" } } } ``` -------------------------------- ### Example jsonschema.json Configuration Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/configuration.markdown This is an example of the jsonschema.json file format. It defines project metadata, default dialect, and schema resolution mappings. ```json { "title": "My JSON Schema Project", "description": "A collection of schemas for my application", "defaultDialect": "https://json-schema.org/draft/2020-12/schema", "resolve": { "https://example.com/schemas/user": "./schemas/user.json", "https://example.com/schemas/product": "./schemas/product.json" }, "ignore": [ "./drafts" ], "lint": { "rules": [ "./rules/require_type.json" ] } } ``` -------------------------------- ### Install all declared dependencies Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/install.markdown Fetches all schemas listed in the `jsonschema.json` configuration file, bundles them, and writes them to their specified local paths. A `jsonschema.lock.json` file is created or updated to record installed dependency hashes. ```sh jsonschema install ``` -------------------------------- ### Install Google Test Project Source: https://github.com/sourcemeta/jsonschema/blob/main/vendor/core/vendor/googletest/googletest/CMakeLists.txt Installs the gtest and gtest_main targets as part of the project. This makes the libraries available for use in other projects. ```cmake install_project(gtest gtest_main) ``` -------------------------------- ### Example JSON BinPack output (hex dump) Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/encode.markdown The resulting binary output of encoding the example JSON document, displayed as a hex dump. Note that this command is experimental. ```text $ xxd output.binpack 00000000: 1308 7665 7273 696f 6e37 02 ..version7. ``` -------------------------------- ### Install via GitHub Actions Source: https://github.com/sourcemeta/jsonschema/blob/main/README.markdown Integrate the JSON Schema CLI into your GitHub Actions workflow. ```yaml - uses: sourcemeta/jsonschema@vX.Y.Z ``` ```yaml - name: Checkout Repository uses: actions/checkout@v4 - name: Install the JSON Schema CLI uses: sourcemeta/jsonschema@v15.8.0 # Then use as usual - run: jsonschema fmt path/to/schemas --check ``` -------------------------------- ### Install CMake Package Configuration Files Source: https://github.com/sourcemeta/jsonschema/blob/main/vendor/core/vendor/googletest/googletest/CMakeLists.txt Configures and installs CMake package configuration files (Config.cmake and ConfigVersion.cmake) if the INSTALL_GTEST option is enabled. This allows other projects to find and use Google Test via find_package(). ```cmake if (INSTALL_GTEST) include(CMakePackageConfigHelpers) set(targets_export_name ${cmake_package_name}Targets CACHE INTERNAL "") set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated" CACHE INTERNAL "") set(cmake_files_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${cmake_package_name}") set(version_file "${generated_dir}/${cmake_package_name}ConfigVersion.cmake") write_basic_package_version_file(${version_file} VERSION ${GOOGLETEST_VERSION} COMPATIBILITY AnyNewerVersion) install(EXPORT ${targets_export_name} COMPONENT "${PROJECT_NAME}" NAMESPACE ${cmake_package_name}:: DESTINATION ${cmake_files_install_dir}) set(config_file "${generated_dir}/${cmake_package_name}Config.cmake") configure_package_config_file("${gtest_SOURCE_DIR}/cmake/Config.cmake.in" "${config_file}" INSTALL_DESTINATION ${cmake_files_install_dir}) install(FILES ${version_file} ${config_file} COMPONENT "${PROJECT_NAME}" DESTINATION ${cmake_files_install_dir}) endif() ``` -------------------------------- ### Example Schema with Remote Reference Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/bundle.markdown This JSON schema references a remote schema located at `https://example.com/string`. ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "$ref": "https://example.com/string" } ``` -------------------------------- ### Example Encoded Binary Data Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/decode.markdown This shows the hexadecimal representation of a sample binary file that can be decoded. ```text $ xxd output.binpack 00000000: 1308 7665 7273 696f 6e37 02 ..version7. ``` -------------------------------- ### Formatted JSON Schema Example Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/format.markdown This is the same JSON Schema as above, but after being formatted by `jsonschema fmt`, demonstrating improved consistency and readability. ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://example.com/iso8601/v1.json", "title": "ISO 8601 four-digit year (YYYY)", "type": "string", "pattern": "^(?!0000)\d{4}$" } ``` -------------------------------- ### Conditional IDNA Library Installation Source: https://github.com/sourcemeta/jsonschema/blob/main/vendor/core/src/core/idna/CMakeLists.txt Conditionally installs the `idna` library if the `SOURCEMETA_CORE_INSTALL` variable is set. This allows for selective installation of the IDNA module. ```cmake if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME idna) endif() ``` -------------------------------- ### Conditional Library Installation Source: https://github.com/sourcemeta/jsonschema/blob/main/vendor/blaze/src/foundation/CMakeLists.txt Conditionally installs the library if the BLAZE_INSTALL variable is set. This is used to control whether the library is installed during the build process. ```cmake if(BLAZE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT blaze NAME foundation) endif() ``` -------------------------------- ### Conditional Installation of Blaze Test Library Source: https://github.com/sourcemeta/jsonschema/blob/main/vendor/blaze/src/test/CMakeLists.txt Conditionally installs the sourcemeta_library for the Blaze test project if the BLAZE_INSTALL flag is set. This ensures the library is only installed when explicitly requested. ```cmake if(BLAZE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT blaze NAME test) endif() ``` -------------------------------- ### Example JSON document Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/encode.markdown A simple JSON object used as an example for encoding. ```json { "version": 2.0 } ``` -------------------------------- ### Example Invalid Schema Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/metaschema.markdown A fictitious JSON Schema example with an invalid 'type' property, demonstrating a common validation error. ```json { "$schema": "http://json-schema.org/draft-04/schema#", "type": 1 } ``` -------------------------------- ### Install a specific dependency Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/install.markdown Add a dependency by providing its URI and the local path where it should be saved. This command also updates the `jsonschema.json` configuration file. ```sh jsonschema install https://schemas.sourcemeta.com/sourcemeta/std/v0/jsonrpc/v2.0/response ./vendor/response.json ``` -------------------------------- ### Example Draft 3 Schema Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/upgrade.markdown This is an example of a JSON Schema written in Draft 3. It serves as input for demonstrating the upgrade process. ```json { "$schema": "http://json-schema.org/draft-03/schema#", "id": "https://example.com", "type": "object", "properties": { "name": { "type": "string", "minLength": 1, "required": true }, "born": { "$ref": "#/definitions/year" } }, "definitions": { "year": { "type": "integer", "minimum": 1900, "divisibleBy": 1 } } } ``` -------------------------------- ### Example of Inconsistent JSON Schema Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/format.markdown This example shows a JSON Schema with inconsistent indentation, spacing, and keyword ordering, which can be improved by the `jsonschema fmt` command. ```json { "$schema":"https://json-schema.org/draft/2020-12/schema", "type": "string","pattern": "^(?!0000)\d{4}$", "$id": "https://example.com/iso8601/v1.json", "title": "ISO 8601 four-digit year (YYYY)" } ``` -------------------------------- ### Run via Docker Source: https://github.com/sourcemeta/jsonschema/blob/main/README.markdown Execute the JSON Schema CLI using a Docker container. Mount your schema directory to /workspace. ```sh docker run --interactive --volume "$PWD:/workspace" \ ghcr.io/sourcemeta/jsonschema:vX.Y.Z lint --verbose myschema.json ``` -------------------------------- ### jsonschema upgrade command syntax Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/upgrade.markdown This shows the general syntax and available options for the `jsonschema upgrade` command. Use this to understand the parameters for upgrading schemas. ```sh jsonschema upgrade [--to/-t draft4|draft6|draft7|2019-09|2020-12] [--http/-h] [--verbose/-v] [--debug/-g] [--json/-j] [--header/-H ": "] [--resolve/-r ...] [--default-dialect/-d ] ``` -------------------------------- ### Include Project Directories and Subdirectories Source: https://github.com/sourcemeta/jsonschema/blob/main/vendor/core/vendor/googlebenchmark/CMakeLists.txt Adds the project's include directory and includes the 'src' subdirectory for building targets. ```cmake # Set up directories include_directories(${PROJECT_SOURCE_DIR}/include) # Build the targets add_subdirectory(src) ``` -------------------------------- ### Strict install for CI/CD Source: https://github.com/sourcemeta/jsonschema/blob/main/docs/install.markdown Ensures reproducible installs in CI/CD pipelines by strictly verifying dependencies against the lock file without modifying it. The lock file must exist and all dependencies must match. ```sh jsonschema install --frozen ```