Skip to content

Add a -p j print mode that outputs Exif, IPTC, and XMP metadata as pretty-printed JSON. - #9365

Open
dixflatlinr wants to merge 3 commits into
Exiv2:mainfrom
dixflatlinr:json-output
Open

Add a -p j print mode that outputs Exif, IPTC, and XMP metadata as pretty-printed JSON.#9365
dixflatlinr wants to merge 3 commits into
Exiv2:mainfrom
dixflatlinr:json-output

Conversation

@dixflatlinr

Copy link
Copy Markdown

No description provided.

DF and others added 3 commits June 24, 2026 02:18
- New Print::printJson() method reads image metadata and serializes
it with nlohmann::ordered_json.
- buildMetadatumJson() handles per-tag JSON construction
- serializeMetadataJson() template filters containers by the same
grep/key/unknown flags used by the existing printMetadata() path.
- TestJsonBasicStructure: validates top-level keys, per-tag field presence
and types on DSC_3079.jpg
- TestJsonFileNotFound: verifies correct stderr message and retval=255
for missing files
- TestJsonWithGrepFilter: -g flag restricts tags to matching keys
- TestJsonWithKeyFilter: -K flag limits output to exact key (ordered
-K before -p j to work around printMode_=pmList side-effect at
exiv2.cpp:394)
- TestJsonWithGrepNoMatch: grep with no hits produces empty arrays
- TestJsonIsValidJson: smoke test that stdout is parseable JSON
@kevinbackhouse

Copy link
Copy Markdown
Collaborator

@kmilos: I like this idea of a JSON output mode, because it could be useful for piping Exiv2's output into other tools. What do you think?

Comment on lines +90 to +96
include(FetchContent)
FetchContent_Declare(nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
)
FetchContent_MakeAvailable(nlohmann_json)
message(STATUS "nlohmann_json: fetched from GitHub")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Pretty please, no FetchContent.

@kmilos

kmilos commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

@kevinbackhouse Sure, if it works the same or better than the removed exiv2json... However I have limited bandwidth to test the feature.

P.S. Please don't merge main branch into PRs, the OP should be asked to rebase instead.

@kevinbackhouse

Copy link
Copy Markdown
Collaborator

P.S. Please don't merge main branch into PRs, the OP should be asked to rebase instead.

Sorry about that. I wanted to run the tests, and that seemed to be the easiest way to trigger them.

Comment thread app/actions.cpp
static nlohmann::ordered_json buildMetadatumJson(const Exiv2::Metadatum& md, const Exiv2::Image* pImage) {
nlohmann::ordered_json j;

j["key"] = md.key();
Comment thread app/actions.cpp
nlohmann::ordered_json j;

j["key"] = md.key();
j["group"] = md.groupName();
Comment thread app/actions.cpp

j["key"] = md.key();
j["group"] = md.groupName();
j["name"] = md.tagName();
Comment thread app/actions.cpp
j["key"] = md.key();
j["group"] = md.groupName();
j["name"] = md.tagName();
j["label"] = md.tagLabel();
Comment thread app/actions.cpp
j["group"] = md.groupName();
j["name"] = md.tagName();
j["label"] = md.tagLabel();
j["tag"] = md.tag();
Comment thread app/actions.cpp

nlohmann::ordered_json root;

root["file"] = path_;
Comment thread app/actions.cpp
nlohmann::ordered_json root;

root["file"] = path_;
root["mime"] = image->mimeType();
Comment thread app/actions.cpp

root["file"] = path_;
root["mime"] = image->mimeType();
root["imageWidth"] = image->pixelWidth();
Comment thread app/actions.cpp
root["file"] = path_;
root["mime"] = image->mimeType();
root["imageWidth"] = image->pixelWidth();
root["imageHeight"] = image->pixelHeight();
Comment thread app/actions.cpp
root["mime"] = image->mimeType();
root["imageWidth"] = image->pixelWidth();
root["imageHeight"] = image->pixelHeight();
root["comment"] = image->comment();
@kmilos

kmilos commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Sorry about that. I wanted to run the tests, and that seemed to be the easiest way to trigger them.

As maintainer/admin you also have the option to rebase rather than merge. (But it is better/nicer the OP keeps their local branch rebased if possible...)

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.

4 participants