https://github.com/python-jsonschema/jsonschema-lexer
A Pygments lexer for JSON Schema
https://github.com/python-jsonschema/jsonschema-lexer
Last synced: 6 months ago
JSON representation
A Pygments lexer for JSON Schema
- Host: GitHub
- URL: https://github.com/python-jsonschema/jsonschema-lexer
- Owner: python-jsonschema
- License: mit
- Created: 2024-02-27T14:31:59.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-30T19:40:24.000Z (7 months ago)
- Last Synced: 2025-07-04T00:32:02.247Z (6 months ago)
- Language: Python
- Size: 128 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- License: COPYING
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
=======================
``jsonschema-lexer``
=======================
|PyPI| |Pythons| |CI|
.. |PyPI| image:: https://img.shields.io/pypi/v/jsonschema-lexer.svg
:alt: PyPI version
:target: https://pypi.org/project/jsonschema-lexer/
.. |Pythons| image:: https://img.shields.io/pypi/pyversions/jsonschema-lexer.svg
:alt: Supported Python versions
:target: https://pypi.org/project/jsonschema-lexer/
.. |CI| image:: https://github.com/python-jsonschema/jsonschema-lexer/workflows/CI/badge.svg
:alt: Build status
:target: https://github.com/python-jsonschema/jsonschema-lexer/actions?query=workflow%3ACI
Introduction
------------
`jsonschema-lexer` provides a lexer for syntax highlighting JSON Schema documents via `Pygments `_.
Usage
-----
Once installed, you can use it in your Python code to highlight JSON Schema documents.
Here's a simple example:
.. code-block:: python
from jsonschema_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)