Getting the individual attributes of a json file from getTokenIdMetadata

const options = { address: "0x26Be870A5c9f45D5b2eEb247bCB19452c623D84b",token_id: r, chain: "rinkeby" };
  let NFTOmeta = await Moralis.Web3API.token.getTokenIdMetadata(options);
  const NFTO = JSON.parse(NFTOmeta);

I am able to get the metadata from the contract but it comes in the { attribute: attribute: } format.
I require NFTOmeta.metadata.attribute but cannot get it and cannot parse it to NFTO.

How do i get the attribute from the metadata to be used as a property in my code

did it return metadata there?

this should work

  let NFTOmeta = await Moralis.Web3API.token.getTokenIdMetadata(options);
  console.log(NFTOmeta.token_id)

yes I get metadata fine but it comes like this…
[
{
“address”: “0x2d30ca6f024dbc1307ac8a1a44ca27de6f797ec22ef20627a1307243b0ab7d09”,
“name”: “Kylin Network”,
“symbol”: “KYL”,
“decimals”: “18”,
“logo”: “https://cdn.moralis.io/eth/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c.png”,
“logo_hash”: “ee7aa2cdf100649a3521a082116258e862e6971261a39b5cd4e4354fcccbc54d”,
“thumbnail”: “https://cdn.moralis.io/eth/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c_thumb.png”,
“block_number”: “string”,
“validated”: “string”
}
]

what i need is NFTOmeta.validated or NFTOmeta.block_number or NFTOmeta.decimals

so after getting it in the { “attribute”: ,“attribute”:} how do i access attribute like NFTOmeta.attribute

it looks like there is a list with one object, you could use list[0].validated

NFTOmeta.metadata works.What I need is NFTOmeta.metadata.validated

Sorry this was a very dumb question from my side

You can get NFTOmeta.metadata from getTokenIdMetadata()

then use NFTO = json.parse(NFTOmeta.metadata)

you can then use NFTO.validated in your program

As per usual thank you for your support cryptokid. Doing the Lord’s work you are.

1 Like