|
1 | 1 | # JSON-DOC
|
2 | 2 |
|
3 |
| -JSON-DOC is a simple and flexible format for storing structured content in JSON files. It is designed to support a wide variety of content types and use cases, such as paragraphs, headings, lists, tables, images, code blocks, HTML and more. |
| 3 | +JSON-DOC is a standardized format for storing structured content in JSON files, inspired by Notion's data model. It supports a wide variety of content types including paragraphs, headings, lists, tables, images, code blocks, and more. |
4 | 4 |
|
5 |
| -JSON-DOC is an attempt to standardize the data model used by [Notion](https://notion.so). |
| 5 | +## Overview |
| 6 | + |
| 7 | +This project provides: |
| 8 | + |
| 9 | +1. **JSON Schema Specification**: Complete schema definitions for all JSON-DOC structures |
| 10 | +2. **Python Implementation**: Full-featured Python library with validation and conversion tools |
| 11 | +3. **TypeScript Implementation**: TypeScript library with React renderer components |
| 12 | +4. **Format Converters**: Tools to convert between JSON-DOC and other formats (HTML, Markdown, etc.) |
6 | 13 |
|
7 | 14 | ## Installation
|
8 | 15 |
|
9 |
| -Install the package from PyPI: |
| 16 | +### Python Package |
10 | 17 |
|
11 | 18 | ```bash
|
12 | 19 | pip install python-jsondoc
|
13 | 20 | ```
|
14 | 21 |
|
| 22 | +### TypeScript Package |
| 23 | + |
| 24 | +```bash |
| 25 | +npm install @textcortex/jsondoc |
| 26 | +``` |
| 27 | + |
| 28 | +## Quick Start |
| 29 | + |
| 30 | +### Python |
| 31 | + |
| 32 | +```python |
| 33 | +from jsondoc import load_json_doc, json_doc_dump_json |
| 34 | +from jsondoc.convert.html import convert_html_to_json_doc |
| 35 | + |
| 36 | +# Load a JSON-DOC document |
| 37 | +with open('document.json', 'r') as f: |
| 38 | + doc = load_json_doc(f.read()) |
| 39 | + |
| 40 | +# Convert HTML to JSON-DOC |
| 41 | +html_content = "<h1>Hello World</h1><p>This is a paragraph.</p>" |
| 42 | +json_doc = convert_html_to_json_doc(html_content) |
| 43 | + |
| 44 | +# Serialize back to JSON |
| 45 | +json_str = json_doc_dump_json(json_doc) |
| 46 | +``` |
| 47 | + |
| 48 | +### TypeScript |
| 49 | + |
| 50 | +```typescript |
| 51 | +import { loadJsonDoc, JsonDocRenderer } from '@textcortex/jsondoc'; |
| 52 | +import React from 'react'; |
| 53 | + |
| 54 | +// Load and render a JSON-DOC document |
| 55 | +const App = () => { |
| 56 | + const doc = loadJsonDoc(jsonDocData); |
| 57 | + |
| 58 | + return ( |
| 59 | + <div> |
| 60 | + <JsonDocRenderer document={doc} /> |
| 61 | + </div> |
| 62 | + ); |
| 63 | +}; |
| 64 | +``` |
| 65 | + |
15 | 66 | ## Features
|
16 | 67 |
|
17 |
| -- Documents are represented as a list of blocks |
18 |
| -- Each block is a JSON object |
19 |
| -- A unique identifier for each block by hashing RFC 8785 Canonical JSON |
20 |
| -- Support for nested blocks |
| 68 | +### Core Features |
| 69 | +- **Structured Content**: Documents represented as hierarchical blocks |
| 70 | +- **Rich Text Support**: Text formatting with bold, italic, links, equations, and more |
| 71 | +- **Nested Blocks**: Support for complex document structures with nested content |
| 72 | +- **Schema Validation**: Full JSON Schema validation for all content types |
| 73 | + |
| 74 | +### Supported Block Types |
| 75 | +- **Text Blocks**: Paragraphs, headings (1-3), quotes, code blocks |
| 76 | +- **List Blocks**: Bulleted lists, numbered lists, to-do lists, toggles |
| 77 | +- **Media Blocks**: Images (external URLs and file references), equations |
| 78 | +- **Layout Blocks**: Columns, dividers, tables |
| 79 | +- **Interactive Blocks**: To-do items with checkbox state |
| 80 | +- Check schema/ for all block types |
| 81 | + |
| 82 | +### Format Conversion |
| 83 | +- Convert between JSON-DOC and all other formats with HTML as the intermediate format |
| 84 | + |
| 85 | +## Repository Structure |
| 86 | + |
| 87 | +``` |
| 88 | +. |
| 89 | +├── schema/ # JSON Schema definitions |
| 90 | +├── python/ # Python implementation |
| 91 | +├── typescript/ # TypeScript implementation |
| 92 | +├── docs/ # Documentation |
| 93 | +├── examples/ # Example files and usage |
| 94 | +└── .github/workflows/ # CI/CD pipelines |
| 95 | +``` |
| 96 | + |
| 97 | +## Development |
| 98 | + |
| 99 | +### Python Development |
| 100 | + |
| 101 | +```bash |
| 102 | +# Setup |
| 103 | +cd python |
| 104 | +pip install -e ".[dev]" |
| 105 | + |
| 106 | +# Run tests |
| 107 | +pytest |
| 108 | + |
| 109 | +# Format code |
| 110 | +ruff format . |
| 111 | +ruff check . |
| 112 | + |
| 113 | +# Validate schemas |
| 114 | +python tests/test_validation.py schema |
| 115 | +``` |
| 116 | + |
| 117 | +### TypeScript Development |
| 118 | + |
| 119 | +```bash |
| 120 | +# Setup |
| 121 | +cd typescript |
| 122 | +npm install |
| 123 | + |
| 124 | +# Generate types from schemas |
| 125 | +npm run generate-types |
| 126 | + |
| 127 | +# Build |
| 128 | +npm run build |
| 129 | + |
| 130 | +# Run tests |
| 131 | +npm test |
| 132 | + |
| 133 | +# Format code (runs automatically on commit) |
| 134 | +npm run format |
| 135 | +``` |
| 136 | + |
| 137 | +## Architecture |
| 138 | + |
| 139 | +### JSON-DOC Schema |
| 140 | + |
| 141 | +The format is defined using JSON Schema with these core components: |
| 142 | + |
| 143 | +- **Page**: Top-level container with metadata and children blocks |
| 144 | +- **Block**: Content blocks of various types (paragraph, heading, list, etc.) |
| 145 | +- **Rich Text**: Formatted text content with styling and annotations |
| 146 | +- **File**: External file references for images and attachments |
| 147 | + |
| 148 | +### Implementation Philosophy |
| 149 | +- **Schema-First**: All types generated programmatically from JSON schemas |
| 150 | +- **Validation**: Comprehensive validation using JSON Schema |
| 151 | +- **Serialization**: Perfect round-trip serialization between JSON and typed objects |
| 152 | +- **Extensibility**: Easy to add new block types via schema updates |
| 153 | + |
| 154 | +## Examples |
| 155 | + |
| 156 | +See the [`examples/`](./examples/) directory for: |
| 157 | +- Sample JSON-DOC documents |
| 158 | +- HTML conversion examples |
| 159 | +- Usage patterns and best practices |
| 160 | + |
| 161 | +## Documentation |
| 162 | + |
| 163 | +- [JSON-DOC Specification](./docs/json-doc-spec.md) |
| 164 | +- [Python Implementation Guide](./docs/python-implementation.md) |
| 165 | +- [TypeScript Implementation Guide](./docs/typescript-implementation.md) |
| 166 | +- [Conversion Guide](./docs/conversion.md) |
| 167 | + |
| 168 | +## Contributing |
| 169 | + |
| 170 | +1. Fork the repository |
| 171 | +2. Create a feature branch |
| 172 | +3. Make your changes with tests |
| 173 | +4. Run the full test suite |
| 174 | +5. Submit a pull request |
| 175 | + |
| 176 | +## License |
| 177 | + |
| 178 | +MIT License - see [LICENSE](./LICENSE) for details. |
21 | 179 |
|
22 |
| -## Motivation |
| 180 | +## Acknowledgments |
23 | 181 |
|
24 |
| -TBD |
| 182 | +Inspired by [Notion's](https://notion.so) block-based document model. This project aims to provide an open, standardized format for structured content representation. |
0 commit comments