[SOLVED] How to get readable URI from the metadata in response to API

I have successfully connected to Moralis API and getContractNFTs returned me the metadata as follows.
"metadata": "{\"name\":\"GLB\",\"image\":\"https://gateway.pinata.cloud/ipfs/QmPesx2hv4A3Qqfoo4qP9zgXDKu9qofKCwWEN3LTHukVi1\",\"description\":\"right?\",\"animation_url\":\"https://gateway.pinata.cloud/ipfs/QmZaGXx9BVxusiC6dtXZR4s6r5xpujrg8SiavNxg4oWscA.glb\"}",

But, how can I retrieve the image URI? Why the bunch of \s are injected? How can I remove those and get clean JSON data?

You need to parse that JSON string if you want to be able to use it as an object. E.g. for JavaScript:

const metadata = JSON.parse(result.metadata); // or whatever you called the response object from Moralis API

console.log("metadata", metadata);
console.log("image", metadata.image);
1 Like