Open Walodja1987 opened 1 year ago
Currently, only URLs that end with .json are handled as json. However, there are also URLs, that do not end with .json but still have json content. Here an example: https://nftstorage.link/ipfs/bafkreic5xs3jg3m4poqqikwyslatiyknkevtwyqqzlouokwlslgkiu5nga
.json
Extend the current check by checking whether the content is of json format by parsing the the response data via JSON.parse.
JSON.parse
Dummy code:
async function isJson(url: string): Promise<boolean> { try { const response = ... // Try to parse the content as JSON try { JSON.parse(response.data); return true; } catch (error) { return false; } } }
Currently, only URLs that end with
.json
are handled as json. However, there are also URLs, that do not end with.json
but still have json content. Here an example: https://nftstorage.link/ipfs/bafkreic5xs3jg3m4poqqikwyslatiyknkevtwyqqzlouokwlslgkiu5ngaExtend the current check by checking whether the content is of json format by parsing the the response data via
JSON.parse
.Dummy code: