GET Response is no valid JSON
Hi, I have an problem using the api.resources with 11ty. The result is not a valid JSON string, so I can´t use it for data based collections:
cloudinary.api.resources({
resource_type:'image',
max_results:1
},
function(error, result) {
console.log(result, error);
});
the result:
[{
asset_id: 'd70bd0d9af6c6850a4ab1063824a490f',
public_id: 'cars/2021-002-MB608D-Feuerwehr-LF8_dqjj6u',
format: 'jpg',
version: 1622637912,
resource_type: 'image',
type: 'upload',
created_at: '2021-06-02T12:45:12Z',
bytes: 45170,
width: 640,
height: 480,
url: 'http://res.cloudinary.com/konsumkit/image/upload/v1622637912/cars/2021-002-MB608D-Feuerwehr-LF8_dqjj6u.jpg',
secure_url: 'https://res.cloudinary.com/konsumkit/image/upload/v1622637912/cars/2021-002-MB608D-Feuerwehr-LF8_dqjj6u.jpg'
}]
The entries should be in double quotation marks.
And JSON.stringify() doesn´t work for me.
-
Hi Thomas,
The response from the API is indeed in JSON format and includes double-quotes around strings, for example, after making an HTTP request to `http://api.cloudinary.com/v1_1/<CLOUD NAME>/resources/image/upload?prefix=sample` and the necessary Authorization header, I receive this in the response:{
"resources": [
{
"asset_id": "199ca4f9f4a800affc0a359fec6617ea",
"public_id": "sample",
"format": "jpg",
"version": 1595420636,
"resource_type": "image",
"type": "upload",
"created_at": "2018-09-10T11:10:08Z",
"bytes": 82504,
"width": 864,
"height": 575,
"access_mode": "public",
"url": "http://res.cloudinary.com/<CLOUD_NAME>/image/upload/v1595420636/sample.jpg",
"secure_url": "https://res.cloudinary.com/<CLOUD_NAME>/image/upload/v1595420636/sample.jpg"
},
// etcIn your case, it looks like you're taking the response object from our Node SDK, which was already converted back from a JSON string to Javascript objects in `handle_response` of the API client code.
If you want to use this response object as JSON, you should be able to convert this back to a JSON string yourself, or serialize it another way according to your requirements - may I ask you to try that please?
Thanks,
Stephen0
Post is closed for comments.
Comments
1 comment