Filling metadata from JSON file with specific format

Started by msk, February 16, 2025, 03:17:35 PM

Previous topic - Next topic

msk

Hi everyone

Is there a way to fill in the metadata of an image based on a JSON file that looks like this:

{
  "name": "Portrait #0",
  "description": "",
  "image": "ipfs:///0.png",
  "imageHash": "8df92c0af37bfaa83995cfe38f3f5b9dea51eefa6914dab04a190e3da52cfe48",
  "edition": 0,
  "date": 1739700511163,
  "attributes": [
    {
      "trait_type": "1.0 Background - Outside",
      "value": "Trees"
    },
    {
      "trait_type": "2.1 Background - Curtain",
      "value": "White_Side"
    },
    {
      "trait_type": "11_Torso",
      "value": "BodyType1"
    },
    {
      "trait_type": "4.1 Clothing",
      "value": "Ephesus"
    },
    {
      "trait_type": "5.0 Face",
      "value": "White2025"
    },
    {
      "trait_type": "5.1 Mouth",
      "value": "Lips_Open4_GlossDark"
    },
    {
      "trait_type": "5.3 Eyelid",
      "value": "Bold_Grey_Wing"
    },
    {
      "trait_type": "5.4 Eyeball",
      "value": "Blue_3"
    },
    {
      "trait_type": "5.2 Eyebrows",
      "value": "Eyebrow_3785_L"
    },
    {
      "trait_type": "5.5 Hair",
      "value": "Flth"
    },
    {
      "trait_type": "11. Vig",
      "value": "Vig"
    }
  ],
}

?

I have a set of 10000 images that each of a corresponding JSON file like this.

ALternatively, I also have 1 single JSON file containing the combined metadata of all the 10000 images in this format:

[
  {
    "name": "Portrait #0",
    "description": "Ht",
    "image": "ipfs:///0.png",
    "imageHash": "8df92c0af37bfaa83995cfe38f3f5b9dea51eefa6914dab04a190e3da52cfe48",
    "edition": 0,
    "date": 1739700511163,
    "attributes": [
      {
        "trait_type": "1.0 Background - Outside",
        "value": "Trees"
      },
      {
        "trait_type": "2.1 Background - Curtain",
        "value": "White_Side"
      },
      {
        "trait_type": "11_Torso",
        "value": "BodyType1"
      },
      {
        "trait_type": "4.1 Clothing",
        "value": "Eps"
      },
      {
        "trait_type": "5.0 Face",
        "value": "White2025"
      },
      {
        "trait_type": "5.1 Mouth",
        "value": "Lips_Open4_GlossDark"
      },
      {
        "trait_type": "5.3 Eyelid",
        "value": "Bold_Grey_Wing"
      },
      {
        "trait_type": "5.4 Eyeball",
        "value": "Blue_3"
      },
      {
        "trait_type": "5.2 Eyebrows",
        "value": "Eyebrow_3785_L"
      },
      {
        "trait_type": "5.5 Hair",
        "value": "Floath"
      },
      {
        "trait_type": "11. Vig",
        "value": "Vig"
      }
    ],

  },
  {
    "name": "Portrait #1",
    "description": "Ht",
    "image": "ipfs:///1.png",
    "imageHash": "ee759da08621ac7c48b018d18f63178d222841094c8666d6",
    "edition": 1,
    "date": 1739700511540,
    "attributes": [
      {
        "trait_type": "1.0 Background - Interior",
        "value": "L_Interior_1"
      },
      {
        "trait_type": "11_Torso",
        "value": "BodyType2"
      },
      {
        "trait_type": "4.1 Clothing",
        "value": "Baa"
      },
      {
        "trait_type": "5.0 Face",
        "value": "White2025"
      },
      {
        "trait_type": "5.1 Mouth",
        "value": "Lips_Closed_4"
      },
      {
        "trait_type": "5.3 Eyelid",
        "value": "Smooth_Light"
      },
      {
        "trait_type": "5.4 Eyeball",
        "value": "Hazel_2"
      },
      {
        "trait_type": "5.2 Eyebrows",
        "value": "Eyebrow_3128_G"
      },
      {
        "trait_type": "5.5 Hair",
        "value": "Edelwth"
      },
      {
        "trait_type": "11. Vig",
        "value": "Vig"
      }
    ],
   
  },
  {
    "name": "Portrait #2",
    "description": "",
    "image": "ipfs:///2.png",
    "imageHash": "b61e0d1dfe1655f013c5f30bc8263e26ac1434620c9",
    "edition": 2,
    "date": 17392210,
    "attributes": [
      {
        "trait_type": "1.0 Background - Outside",
        "value": "Moutain"
      },
      {
        "trait_type": "2.1 Background - Curtain",
        "value": "White_Side"
      },
      {
        "trait_type": "11_Torso",
        "value": "BodyType2"
      },
      {
        "trait_type": "4.2 Scarf",
        "value": "Pearl_Collar"
      },
      {
        "trait_type": "4.1 Clothing",
        "value": "ClothesLayerDiffuser"
      },
      {
        "trait_type": "5.0 Face",
        "value": "White2025"
      },
      {
        "trait_type": "5.1 Mouth",
        "value": "Lips_Open_1"
      },
      {
        "trait_type": "5.3 Eyelid",
        "value": "Dual_Wing_Dark"
      },
      {
        "trait_type": "5.4 Eyeball",
        "value": "Green_1"
      },
      {
        "trait_type": "5.2 Eyebrows",
        "value": "Eyebrow_3128"
      },
      {
        "trait_type": "5.5 Hair",
        "value": "Ao_Hess"
      },
      {
        "trait_type": "11. Vig",
        "value": "Vi"
      }
    ],
   

That would then allow me sort/filter by these trait parameters in iMatch.

I've scoured the whole internet as well as watched the iMatch videos and read the Help documents for ways to do this but I haven't found a solution - yet I feel like it should be possible.

Any advice would be very much appreciated!

Mario

You won't find any existing pre-made solution for something like this.

- Which application created these JSON files?
- How does an URI like ipfs:///0.png translate to a file name in your IMatch database?
- Which kind of algorithm was used to calculate "imageHash" and on which data was it built?
- What are these traits?
  Surely not standard metadata. Where should these be stored in the database?

IMatch includes a fully-documented REST interface, allowing users to access IMatch databases from any programming language capable of accessing REST services (Python, PowerShell, curl, Java, JavaScript, C#, C++, ...). See https://www.photools.com/dev-center/doc/imatch/ for more information.

If you have some programming experience or you can hire somebody who does this for you, it should be relatively straightforward to read the JSON files, lookup the file in the database and then store these "traits" somewhere when you know how to answer the questions listed above.


msk

Hi Mario. Thanks for your reply.

- The Json was created with this script https://github.com/nftchef/art-engine
- Realistically I only need the metadata under attributes for the purpose I intend to use this, so would be looking to have a metadata field for "Trait Type" which gets filled with a different "Value"
- Are you familiar with PFP NFTs such as the cryptopunks/boredapes etc? Each image is made of a series of traits stacked on top of each other - so a trait would be a mouth, a pair of eyes, etc. After generating an image with those traits, the script above stores each trait in a json sidecar. My goal is to be able to get Imatch to read that sidecar file, or import the metadata so that I can filter and sort by each trait as part of my quality control process.

My programming skills are very basic but I shall give it a try with the use of an AI maybe. If that fails I'll see about hiring somebody.


"trait_type": "1.0 Background - Outside",
        "value": "Trees"
      },
      {
        "trait_type": "2.1 Background - Curtain",
        "value": "White_Side"
      },
      {
        "trait_type": "11_Torso",
        "value": "BodyType1"
      },
      {
        "trait_type": "4.1 Clothing",
        "value": "Eps"
      },
      {
        "trait_type": "5.0 Face",
        "value": "White2025"
      },
      {
        "trait_type": "5.1 Mouth",
        "value": "Lips_Open4_GlossDark"
      },
      {
        "trait_type": "5.3 Eyelid",
        "value": "Bold_Grey_Wing"
      },
      {
        "trait_type": "5.4 Eyeball",
        "value": "Blue_3"
      },
      {
        "trait_type": "5.2 Eyebrows",
        "value": "Eyebrow_3785_L"
      },
      {
        "trait_type": "5.5 Hair",
        "value": "Floath"
      },
      {
        "trait_type": "11. Vig",
        "value": "Vig"
      }
    ],



Mario

QuoteAre you familiar with PFP NFTs such as the cryptopunks/boredapes etc?
Not really my thing. Probably just another way to part people from their money ;D


QuoteMy goal is to be able to get Imatch to read that sidecar file, or import the metadata so that I can filter and sort by each trait as part of my quality control process.
Since there seem to be multiple trait types per file, you'll need to use a repeatable tag like keywords to store this info. Or yous setup an per-file Attribute Set with a "Trait" Attribute of type text and store the info there.

IMatch ships with sample scripts showing how to modify metadata, how to modify Attribute data and more. Enable the developer mode in Edit menu > Preferences > Application and start with the documentation: https://www.photools.com/developer-center/


Jingo

I'd be happy to work on a script for you given some time... the script could read each JSON file that is linked to the image by filename and then stores each trait in the database for that image... it could be stored as a keyword, attribute, category, etc...  Let me know!

axel.hennig

I haven't really followed fully, but it more or less looks like a one-time-task. Wouldn't it make more sense (aka quicker) to try to make a csv out of the json (only attributes out of the json is needed) and import that into IMatch-Atttributes?