Skip to content

MaD: add script to convert YAML data extensions to JSON - #23102

Open
nickrolfe wants to merge 1 commit into
mainfrom
nickrolfe/json-data-extension-script
Open

nickrolfe wants to merge 1 commit into
mainfrom
nickrolfe/json-data-extension-script

Conversation

@nickrolfe

Copy link
Copy Markdown
Contributor

This is the script I used to perform the conversions in the PRs below. I'm adding it to the repo in case anyone else needs to convert models, here or elsewhere, in the future.

I don't particularly recommend reviewing the script itself — it was generated by Copilot and I certainly haven't. It's complicated because it preserves comments and produces a non-standard JSON formatting in order to get each tuple on one line. But it worked well enough that I was able to verify all the conversions in the PRs below, and the only manual edits required were a few tweaks to comment locations.

You may find it surprisingly complex, but that's mainly because:
- it's vibe-coded
- it preserves comments
- it formats the JSON so that it pretty-prints nicely, but with one line
  per tuple

I intend to manually verify all conversions made with it.
@nickrolfe nickrolfe added the no-change-note-required This PR does not need a change note label Nov 11, 2026
@nickrolfe
nickrolfe marked this pull request as ready for review November 11, 2026 15:03
@nickrolfe
nickrolfe requested a review from a team as a code owner November 11, 2026 15:03
Copilot AI auto review requested due to automatic review settings November 11, 2026 15:03

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.

🟡 Changes recommended

Unresolved critical findings allow existing JSON files to be overwritten, temporary-file symlinks to redirect writes, and manifest matches outside the pack to cause external file writes or deletions.

3 open issues
What changed in this PR

Adds the reusable converter used in the linked model migrations, supporting CodeQL’s faster-loading JSON data extensions.

Changes:

  • Converts YAML models to JSON with comment preservation and one tuple per line.
  • Accepts explicit files or discovers models through a qlpack.yml manifest.
  • Adds JSON manifest patterns while retaining YAML patterns, with optional deletion of converted sources.
File Description
misc/​scripts/​convert-yaml-data-extensions-to-json.py Adds the conversion command, comment-aware formatting, and manifest updates.

Review effort: Balanced (auto)

Comment on lines +249 to +254
temporary = path.with_name(f".{path.name}.tmp")
try:
temporary.write_text(contents, encoding="utf-8")
temporary.replace(path)
finally:
temporary.unlink(missing_ok=True)

def convert_data_extension(source: Path, delete_yaml: bool = False) -> Path:
"""Convert a YAML data extension to JSON, optionally removing the source."""
target = source.with_suffix(".json")
Comment on lines +277 to +286
files = set()
for pattern in patterns:
if not isinstance(pattern, str):
raise ValueError(f"dataExtensions pattern is not a string: {pattern!r}")
files.update(
match.resolve()
for match in path.parent.glob(pattern.lstrip("/"))
if match.is_file() and match.suffix in {".yml", ".yaml"}
)
return sorted(files)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants