How to update NFT metadata json object values

Hello, how can I add a new key value pair in a json object? I am uploading a list of NFT metadata to IPFS and I need to add a new key value pair with the IPFS url.

:computer: Environment


{    "Name": "Solid Cat",
    "HP": "100",
    "Atk": "100",
    "Def": "100" ,

Example Output:

    "Name": "Solid Cat",
    "HP": "100",
    "Atk": "100",
    "Def": "100" ,

The code reads the values of various NFT metadata from anartwork json, loops and uploads each to IPFS and returns anuploaded.jsonwhich containes key value pairs of each IPFS hash to the original NFT metadata. Instead I just want theuploaded.json
to have same list of NFT data as inartwork.jsonplus theupdateInfokey and the IPFS url, which does not have to be pinata specifically

const ipfs = ipfsAPI({host: '', port: '5001', protocol: 'https' })
const main = async () => {
  let allAssets = {}
  console.log("\n\n Loading artwork.json...\n");
  const artwork = JSON.parse(fs.readFileSync('./artwork.json').toString())
  for(let a in artwork){
    console.log("  Uploading "+artwork[a].name+"...")
    const stringJSON = JSON.stringify(artwork[a])
    const uploaded = await ipfs.add(stringJSON)
    console.log("   "+artwork[a].name+" ipfs:",uploaded.path)
    allAssets[uploaded.path] = artwork[a]
  console.log("\n Creating file with all the uploaded hashes...")

Hi @Altaergo,

You may want to try StackExchange as this is more of a JavaScript question.

1 Like