Skip to main content

A Pygments lexer for JSON Schema

Project description

PyPI version Supported Python versions Build status

Introduction

jsonschema-lexer is a Python package that provides a JSON Schema lexer for syntax highlighting JSON Schema documents based on the 2020-12 dialect. It utilizes Pygments, a syntax highlighting library, to tokenize JSON Schema documents according to the JSON Schema specification.

Usage

Once installed, you can use it in your Python code to highlight JSON Schema documents.

Here’s a simple example:

# Import the JSONSchemaLexer class from the package
from jsonschema_lexer.lexer import JSONSchemaLexer

from rich.console import Console
from rich.syntax import Syntax

console = Console()

code = """
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.com/product.schema.json",
  "title": "Product",
  "description": "A product from Acme's catalog",
  "type": "object",
  "properties": {
    "productId": {
      "description": "The unique identifier for a product",
      "type": "integer"
    },
    "productName": {
      "description": "Name of the product",
      "type": "string"
    }
  }
}
"""

syntax = Syntax(code, lexer=JSONSchemaLexer(), background_color="default", word_wrap=True)
console.print(syntax)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonschema_lexer-0.1.0.tar.gz (8.7 kB view hashes)

Uploaded Source

Built Distribution

jsonschema_lexer-0.1.0-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page