feat: add JSON output format for diagram export - #2850
Open
pauldotknopf wants to merge 1 commit into
Open
Conversation
Add .json as a supported export format that serializes the d2target.Diagram to pretty-printed JSON. This provides a structured, machine-readable representation of the rendered diagram including all shapes, connections, positions, and styling. The JSON output skips SVG rendering entirely — it marshals the already-computed diagram after layout and export, making it the fastest output format. Changes: - d2cli/export.go: Register JSON extension (.json) in supported extensions, stdout format map, and supported stdout formats - d2cli/main.go: Add JSON handling in _render() that marshals diagram via json.MarshalIndent and writes to output - d2cli/help.go: Add file.json to usage and description text - d2cli/export_test.go: Add test cases for file and stdout JSON output Usage: d2 input.d2 output.json d2 --format json input.d2 -
Author
|
context: I need to consume that d2 layout from another language/system. I'll be using the JSON format to load into neo4j, so that I can have an LLM reason against it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add .json as a supported export format that serializes the d2target.Diagram to pretty-printed JSON. This provides a structured, machine-readable representation of the rendered diagram including all shapes, connections, positions, and styling.
The JSON output skips SVG rendering entirely — it marshals the already-computed diagram after layout and export, making it the fastest output format.
Changes:
Usage:
d2 input.d2 output.json d2 --format json input.d2 -