Skip to content

🐛 fix(mq-run): output proper JSON for non-Markdown values with -F json#1750

Merged
harehare merged 4 commits into
mainfrom
fix/json-output-format
May 16, 2026
Merged

🐛 fix(mq-run): output proper JSON for non-Markdown values with -F json#1750
harehare merged 4 commits into
mainfrom
fix/json-output-format

Conversation

@harehare

Copy link
Copy Markdown
Owner

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:

  • runtime_values_to_json(): encapsulates JSON serialization logic
  • build_markdown(): constructs and configures the Markdown struct

Add tests for JSON output with Markdown input, JSON object input, and JSON array input.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to null. This regresses queries that return Markdown children as an array (for example .children/attr("children")), which previously went through runtime_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 json now 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(),

Comment thread crates/mq-run/src/cli.rs
harehare and others added 2 commits May 16, 2026 23:23
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_json always serializes json_values as 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))

Comment thread crates/mq-run/src/cli.rs Outdated
@harehare harehare force-pushed the fix/json-output-format branch from 3b76a77 to 1b704b6 Compare May 16, 2026 14:43
@harehare harehare merged commit 85856d7 into main May 16, 2026
8 checks passed
@harehare harehare deleted the fix/json-output-format branch May 16, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants