Add a -p j print mode that outputs Exif, IPTC, and XMP metadata as pretty-printed JSON. - #9365
Add a -p j print mode that outputs Exif, IPTC, and XMP metadata as pretty-printed JSON.#9365dixflatlinr wants to merge 3 commits into
Conversation
- 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
|
@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? |
| 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") |
There was a problem hiding this comment.
Pretty please, no FetchContent.
|
@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. |
Sorry about that. I wanted to run the tests, and that seemed to be the easiest way to trigger them. |
| static nlohmann::ordered_json buildMetadatumJson(const Exiv2::Metadatum& md, const Exiv2::Image* pImage) { | ||
| nlohmann::ordered_json j; | ||
|
|
||
| j["key"] = md.key(); |
| nlohmann::ordered_json j; | ||
|
|
||
| j["key"] = md.key(); | ||
| j["group"] = md.groupName(); |
|
|
||
| j["key"] = md.key(); | ||
| j["group"] = md.groupName(); | ||
| j["name"] = md.tagName(); |
| j["key"] = md.key(); | ||
| j["group"] = md.groupName(); | ||
| j["name"] = md.tagName(); | ||
| j["label"] = md.tagLabel(); |
| j["group"] = md.groupName(); | ||
| j["name"] = md.tagName(); | ||
| j["label"] = md.tagLabel(); | ||
| j["tag"] = md.tag(); |
|
|
||
| nlohmann::ordered_json root; | ||
|
|
||
| root["file"] = path_; |
| nlohmann::ordered_json root; | ||
|
|
||
| root["file"] = path_; | ||
| root["mime"] = image->mimeType(); |
|
|
||
| root["file"] = path_; | ||
| root["mime"] = image->mimeType(); | ||
| root["imageWidth"] = image->pixelWidth(); |
| root["file"] = path_; | ||
| root["mime"] = image->mimeType(); | ||
| root["imageWidth"] = image->pixelWidth(); | ||
| root["imageHeight"] = image->pixelHeight(); |
| root["mime"] = image->mimeType(); | ||
| root["imageWidth"] = image->pixelWidth(); | ||
| root["imageHeight"] = image->pixelHeight(); | ||
| root["comment"] = image->comment(); |
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...) |
No description provided.