SpruceKit
SpruceID
  • 🌲SpruceKit Introduction
    • Decentralized Identity Overview
    • Glossary
  • ⚡Quickstart
  • SpruceKit Mobile
    • SpruceKit Showcase App
      • Installation
      • Getting Started
      • Issue a Showcase Credential
      • Present a Showcase Credential
    • SpruceKit Mobile SDK
      • Introduction
      • Core Components
        • StorageManager
        • KeyManager
        • CredentialPack
        • Card
        • IsoMdlPresentation
        • mDocReader/IsomDLReader
        • Document Scanner
      • SpruceKit iOS SDK
        • Installation
        • Build a Wallet
          • Accept a W3C VC
          • Present a W3C VC
          • Present mDL in-person/offline
          • Present an mDL over the internet
        • Build a Verifier
          • Verify a W3C VC
          • Verify an mDL in-person/offline
          • Verify an mDL over the internet
      • SpruceKit Android SDK
        • Installation
        • Build a Wallet
          • Accept a W3C VC
          • Present a W3C VC
          • Present an mDL in-person/offline
          • Present an mDL over the internet
        • Build a Verifier
          • Verify a W3C VC
          • Verify an mDL in-person/offline
          • Verify an mDL over the internet
  • Verifiable Digital Credentials
    • ⚙️DIDKit
      • Installation
      • Core Concepts
      • DID Methods
      • Runtime Configuration
      • Specifications and Dependencies
      • Quickstart
      • DIDKit Packages
        • Command Line Interface
        • HTTP Server
        • Rust Crate
        • C Interface
        • Java and Android
        • Python
        • Javascript
      • DIDKit Examples
        • Core Functions (CLI)
        • Core Functions (HTTP)
        • did-web in minutes
        • Batch Generation & Verification
    • 🪪ISO mDL
      • Quickstart
      • Core Concepts
      • User Guide
  • Schema Definition Language
    • 🔗TreeLDR
      • TreeLDR Quickstart
        • First Schema
        • Compilation into JSON Schema
        • Compilation into JSON-LD Context
        • Writing a Layout
        • Simple Rust Integration
      • Types
        • Literal Types
      • Layouts
        • Primitive Layouts
        • Literal Layouts
        • Enumeration
        • Array Layout
        • References
      • Compiling
        • Schema Definition Formats
          • JSON Schema
          • JSON-LD Context
          • Resource Description Framework (RDF)
        • Programming Languages
          • Compiling to Rust
      • RDF Vocabulary
      • 💡TreeLDR Basics
        • Types and Layouts
        • Properties
        • Syntax
  • Witness for Credential Claims
    • 🔭Rebase
      • Core Library
      • Rust Client/Witness SDK
      • WASM Client SDK
      • Simple "Basic Post" Schema
      • DNS Witness Flow Schema
  • References
    • Contributing
    • Code of Conduct
Powered by GitBook
On this page
  • Generating a JSON Schema
  • Importing a JSON Schema

Was this helpful?

  1. Schema Definition Language
  2. TreeLDR
  3. Compiling
  4. Schema Definition Formats

JSON Schema

PreviousSchema Definition FormatsNextJSON-LD Context

Last updated 1 year ago

Was this helpful?

is a JSON-based schema definition language. It defines the expected layout of a JSON document, but does not describe its semantics.

{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"$id": "https://example.com/example.schema.json",
	"description": "Example schema",
	"type": "object",
	"properties": [
		"foo": {
			"description": "Schema of the `foo` property",
			"type": "string"
		}
	]
}

TreeLDR can generate a JSON Schema from a TreeLDR layout. It can also import a TreeLDR layout from a JSON Schema, although it will result in an orphan layout: a layout not associated to any type, and without any semantic information. For instance, the above JSON Schema is equivalent to the following TreeLDR layout:

/// Example schema.
layout Example {
	/// Schema of the `foo` property.
	foo: xs:string
}

Generating a JSON Schema

Generating a JSON-LD context is done by using the json-schema subcommand of the command line utility after the list of inputs, and by specifying what layout should be turned into a JSON Schema.

tldrc -i input1 ... -i inputN json-schema path/to/Layout

For instance, consider the following layout for the schema:BlogPosting type:

// example/basic_post.tldr
base <https://example.com/>;
use <https://schema.org/> as schema;

layout BasicPost for schema:BlogPosting {
	/// Title of the post.
	schema:title: schema:Text,

	/// Content of the post.
	schema:body: schema:Text
}

Use the following command to generate JSON Schema context:

tldrc -i example/basic_post.tldr -i example/schema.org.tldr json-schema https://example.com/BasicPost 

Running that generates:

{
	"$id": "https://example.com/BasicPost",
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"properties": {
		"body": {
			"description": "Content of the post.",
			"type": "string"
		},
		"title": {
			"description": "Title of the post.",
			"type": "string"
		}
	},
	"title": "Basic Blog Post.",
	"type": "object"
}

The resulting schema loses any Linked Data information.

Importing a JSON Schema

The TreeLDR compiler (tldrc) can import a JSON Schema like any other input document using the -i option. This will import the JSON Schema as an orphan TreeLDR layout. For instance, we can import and export back the previously generate JSON Schema above, and we will get back the same document:

tldrc -i examples/basic_post.schema.json json-schema https://example.com/BasicPost
🔗
JSON Schema