Export your knack database schema to JSON-Schema, YAML, DBML, Mermaid ERD

Howdy All,

I’ve added some features to knack-sleuth to export the schema in a variety of ways

I introduced knack-sleuth here: YAKET - Yet Another Knack Exploration Tool … except I called it knack-sleuth … and it’s Command-Line / for the terminal

Details on new features.

export-schema:

The schema as it appears to knack itself. Only really json-schema export format.

Basically the output of https://api.knack.com/v1/applications/{{Knack-Application-Id}} but I built a Pydantic Model around it and this spits out the JSON Schema associated with my internal Python Pydantic Models.

TIP: I’ve seen posts on the forum about how to get your App Schema and it seems fairly convoluted, if you want the raw JSON schema as Knack Serves, just update the URL above with your Application ID and paste into any browser, it’ll display the JSON and you copy the text from your browser.

export-db-schema:

Here is the output from --help

Export your application's database schema (how your app looks to you).                                                              
                                                                                                                                     
 This generates a user-facing schema representation of your database structure, similar to what you see in the Knack builder. It     
 analyzes objects (tables), fields (columns), and connections (relationships) to construct an ER diagram or schema document. This is 
 NOT Knack's internal metadata format (use export-schema for that).                                                                  
 
Supported formats:                                                                                                                  
 - json: JSON Schema format with full relationship metadata                                                                          
 - dbml: Database Markup Language for ER diagram generation (dbdiagram.io)                                                           
 - yaml: Human-readable YAML representation                                                                                          
 - mermaid: Mermaid ER diagram syntax (GitHub, GitLab, VS Code compatible)                                                           
 
Detail levels:                                                                                                                      
 - structural: Objects/tables and relationships only (no attributes)                                                                 
 - minimal: Objects and connections only (high-level structure)                                                                      
 - compact: Key fields (identifier, required, connections)                                                                           
 - standard: All fields with complete details (default)                                                                              


 Examples:                                                                                                                           
 # Export from file to JSON Schema     knack-sleuth export-db-schema app_export.json                                                 
 # Export to DBML for ER diagram with minimal detail     knack-sleuth export-db-schema app_export.json --format dbml --detail        
 minimal -o schema.dbml                                                                                                              
 # Export to Mermaid ER diagram     knack-sleuth export-db-schema app_export.json --format mermaid -o schema.mmd                     
 # Export compact view to YAML     knack-sleuth export-db-schema app_export.json --format yaml --detail compact                      
 # Export to YAML     knack-sleuth export-db-schema app_export.json --format yaml -o schema.yaml                                     
 # Load from Knack API and export (no API key needed for public metadata)     knack-sleuth export-db-schema --app-id YOUR_APP_ID -f  
 dbml 

And my favorite

export-schema-subgraph

output form --help


 Usage: knack-sleuth export-schema-subgraph [OPTIONS] [FILE_PATH]                                                                    
                                                                                                                                     
 Export a subgraph of the database schema starting from a specific object.                                                           
                                                                                                                                     
 This generates a schema representation of a subset of the database, starting from a specified object and including all objects      
 connected to it up to a specified depth.                                                                                            
 

Depth levels:                                                                                                                       
 - depth=0: Starting object + all directly connected objects (default)                                                               
 - depth=1: Above + connections of those directly connected objects                                                                  
 - depth=2: One more level deep (maximum recommended)                                                                                
 - depth>2: Not recommended - use export-db-schema for full schema                                                                   
 

Supported formats:                                                                                                                  
 - json: JSON Schema format with full relationship metadata                                                                          
 - dbml: Database Markup Language for ER diagram generation (dbdiagram.io)                                                           
 - yaml: Human-readable YAML representation                                                                                          
 - mermaid: Mermaid ER diagram syntax (GitHub, GitLab, VS Code compatible)                                                           
 

Detail levels:                                                                                                                      
 - structural: Objects/tables and relationships only (no attributes)                                                                 
 - minimal: Objects and connections only (high-level structure)                                                                      
 - compact: Key fields (identifier, required, connections)                                                                           
 - standard: All fields with complete details (default)                                                                              
 

Examples:                                                                                                                           
 # Export Events and direct connections to YAML     knack-sleuth export-schema-subgraph --object Events -f yaml -o events.yaml       
 # Export Events subgraph with depth 2 to Mermaid     knack-sleuth export-schema-subgraph --object Events --depth 2 -f mermaid       
 # Export from API using object key     knack-sleuth export-schema-subgraph --app-id YOUR_APP_ID --object object_12 -f dbml          
 # Export with minimal detail level     knack-sleuth export-schema-subgraph app.json --object Events --detail minimal -f yaml  

I’ve mostly been using mermaid ERD.

If you have uv installed, I’d say give this a shot

uvx knack-sleuth@latest   export-schema-subgraph --object "Object Name" --app-id <Your Application ID> --detail structural --format mermaid

and go to mermaid.live to render it.

NOTE: I use obsidian for my notes, and the mermaid diagrams work inside Obsidian (which was the real driver for subgraphs, so I could add more rich context and content to my notes.

This is a screenshot from mermaid of a subgraph export of an app that has 60+ tables in it.

Happy sleuthing :slight_smile:

I think I’ve solved most of my immediate issues which drove me to create knack-sleuth… but if you have challenges that need additional features, that seem logical to add to knack-sleuth happy to discuss it, just DM me.

Cheers,
Tyler

1 Like