Fix JSON output: omit null values and add trailing newline#149
Merged
amc-corey-cox merged 2 commits intomainfrom Mar 10, 2026
Merged
Fix JSON output: omit null values and add trailing newline#149amc-corey-cox merged 2 commits intomainfrom
amc-corey-cox merged 2 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns JSON/JSONL output behavior with existing YAML behavior by omitting None-valued keys, and ensures JSON/JSONL CLI output ends with a trailing newline (fixing console prompt “run-on” and Unix text conventions).
Changes:
- Add
_strip_nulls()helper to recursively removeNonevalues from dictionaries prior to JSON/JSONL serialization. - Apply null-stripping across all JSON/JSONL stream writer code paths (
JSONStreamWriter,JSONLStreamWriter,json_stream,jsonl_stream) and CLIdump_output(). - Ensure
dump_output()JSON and JSONL output always ends with\n, and add tests covering null suppression + newline behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/linkml_map/writers/output_streams.py |
Adds _strip_nulls() and applies it to all JSON/JSONL streaming serialization paths. |
src/linkml_map/cli/cli.py |
Updates dump_output() JSON/JSONL branches to strip nulls and append trailing newline. |
tests/test_writers/test_output_streams.py |
Adds unit tests asserting JSON/JSONL streaming omits None keys (including nested dicts). |
tests/test_cli/test_cli.py |
Adds CLI-level tests for trailing newline and null suppression in dump_output(). |
Comments suppressed due to low confidence (1)
tests/test_cli/test_cli.py:7
- The standard-library imports in this file are now out of order (adding
import jsonbeforefrom collections.abc ...breaks Ruff/isort sorting). Please reorder the import block to match the project’s isort configuration so linting passes.
"""Tests all command-line subcommands."""
import json
from collections.abc import Generator
from pathlib import Path
import re
from typing import Any, Optional, Union
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.
Summary
Nonevalues, matching YAML serialization behavior. Slot suppression viaexpr: None if ...now works correctly for JSON output.Changes
_strip_nulls()helper inoutput_streams.pythat recursively removesNonevalues from dicts before JSON serializationdump_output(),JSONStreamWriter,JSONLStreamWriter,json_stream(),jsonl_stream()\nto JSON/JSONL output indump_output()(streaming paths already had this)Test plan
test_output_streams.py— null suppression for all JSON/JSONL writers + nested nullstest_cli.py— trailing newline and null suppression viadump_output()🤖 Generated with Claude Code