🐛 fix(mq-run): output proper JSON for non-Markdown values with -F json#1750
Merged
Conversation
Non-Markdown runtime values (Dict, Array, etc.) from json_parse() were being
converted to Markdown text nodes and serialized as Markdown AST structure
({"type": "Text", "value": "...", "position": null}) instead of proper JSON.
ff5c7e5 to
8a81e58
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates mq-run JSON output so non-Markdown runtime values are serialized as JSON values instead of Markdown AST text nodes.
Changes:
- Adds
runtime_values_to_json()for JSON serialization. - Refactors Markdown construction into
build_markdown(). - Adds CLI tests for JSON output from Markdown and JSON inputs.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
crates/mq-run/src/cli.rs |
Refactors output printing and changes JSON serialization behavior. |
crates/mq-run/Cargo.toml |
Adds serde_json as a direct dependency for mq-run. |
Cargo.lock |
Records the new mq-run dependency entry. |
Comments suppressed due to low confidence (2)
crates/mq-run/src/cli.rs:863
- Arrays that contain Markdown runtime values now serialize those nested Markdown values through
RuntimeValue::to_json_value(), which maps Markdown tonull. This regresses queries that return Markdown children as an array (for example.children/attr("children")), which previously went throughruntime_value_to_nodes()/Markdown::to_json()and emitted Markdown AST objects instead of[null, ...]. The JSON conversion needs to handle nested Markdown values recursively or preserve the existing Markdown-node flattening path for arrays containing Markdown.
_ => v.clone().to_json_value(),
crates/mq-run/src/cli.rs:863
- Known expandable typed dicts (such as section/table objects) no longer go through
runtime_value_to_nodes()in JSON mode, so-F jsonnow emits their internal dict representation instead of the Markdown AST nodes the CLI output path previously produced. This conflicts with the documented behavior that section objects are automatically expanded in CLI output and makes JSON output inconsistent with Markdown/HTML/Text formats.
_ => v.clone().to_json_value(),
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
crates/mq-run/src/cli.rs:869
runtime_values_to_jsonalways serializesjson_valuesas a JSON array, so a single non-Markdown value still becomes wrapped (for example{"id":1}becomes[{"id":1}], and an input array becomes[[...]]). This contradicts the intended behavior and the new object/array tests will fail because they expect the single non-Markdown value to be emitted directly.
serde_json::to_string_pretty(&serde_json::Value::Array(json_values))
.map_err(|e| miette!("Failed to serialize to JSON: {}", e))
3b76a77 to
1b704b6
Compare
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.
Non-Markdown runtime values (Dict, Array, etc.) from json_parse() were being converted to Markdown text nodes and serialized as Markdown AST structure ({"type": "Text", "value": "...", "position": null}) instead of proper JSON.
Fix: in -F json mode, Markdown nodes are still wrapped in an array as Markdown AST JSON, while non-Markdown values are serialized directly via to_json_value(). A single non-Markdown value is output directly to avoid double-wrapping (e.g. a JSON array from json_parse() does not become [[...]]).
Also refactor print() into a single match expression using helper functions:
Add tests for JSON output with Markdown input, JSON object input, and JSON array input.