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 8 commits into
Exiv2:mainfrom
dixflatlinr:json-output
Open

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

Conversation

@dixflatlinr

Copy link
Copy Markdown

No description provided.

@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 thread cmake/findDependencies.cmake Outdated
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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ok, done.

@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();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

These alerts seem like a moissanite. Since writes into locally built documents, no reads of untrusted keys....

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...)

DF added 3 commits September 14, 2026 11:41
- 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

I've just rebased this onto main. I also added a commit which will hopefully fix the CodeQL errors.

@dixflatlinr: only some of our build scripts in .github/workflows use conan. On the others you'll need to add something like apt-get install nlohmann-json3-dev to install the package.

dixflatlinr and others added 2 commits October 9, 2026 20:14
Installs nlohmann_json on non-conan CI jobs for:
Alpine, macOS, MSYS2, Cygwin, CodeQL, meson matrix, release

Declares the dependency in meson.build with a wrapdb fallback, adds it to
ci/install_dependencies.sh for all distros, and updates the exiv2-test
reference for the new 'j : JSON output' help line.
@dixflatlinr

Copy link
Copy Markdown
Author

I've just rebased this onto main. I also added a commit which will hopefully fix the CodeQL errors.

@dixflatlinr: only some of our build scripts in .github/workflows use conan. On the others you'll need to add something like apt-get install nlohmann-json3-dev to install the package.

Ok, added the requirements. Check it now with CI please. They ran fine for me.

@mergify

mergify Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@dixflatlinr dixflatlinr left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Required changes added.

@dixflatlinr

Copy link
Copy Markdown
Author

@kevinbackhouse @kmilos CI fixes for nlohmann_json are pushed. The workflow runs for this commit are waiting on maintainer approval before they start. All six Linux configs configure+build, matrix passes all 8 tests.

@dixflatlinr
dixflatlinr requested a review from kmilos November 23, 2026 08:53
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