
I am currently facing an issue after upgrading to 1.4.3 regarding the responseBody
when returning JSON from the function.
So my Node.js function has the following lines:
log(JSON.stringify(myContainers));
return res.json(JSON.stringify(myContainers));
The appwrite log output show the following (as desired) value:
[{"_id":"649808696bca89048c8f0653","name":"Rombergstraße 118","label":"Weihnachtsdeko","uuid":"6a17cb1b-4215-4538-a2ae-0ef8a0af7fc8","location":"Unbekannt","description":"","tags":["test"],"owners":[{"username":"testuser@example.com","name":"Test User","userId":"649807cb6488dc8ff3c5"}],"readUsers":[],"rfid":""},{"_id":"649808696bca89048c8f0654","name":"Bethmannstraße 115","label":"Behälter 2","uuid":"e97b24c3-df68-45ef-a7dd-c830205cfae0","location":"Unbekannt","tags":["test"],"owners":[{"username":"testuser@example.com","name":"Test User","userId":"649807cb6488dc8ff3c5"}],"readUsers":[]}]
But the responseBody
of the request, when using Postman returns:
"responseBody": "\"[{\\\"_id\\\":\\\"649808696bca89048c8f0653\\\",\\\"name\\\":\\\"Rombergstraße 118\\\",\\\"label\\\":\\\"Weihnachtsdeko\\\",\\\"uuid\\\":\\\"6a17cb1b-4215-4538-a2ae-0ef8a0af7fc8\\\",\\\"location\\\":\\\"Unbekannt\\\",\\\"description\\\":\\\"\\\",\\\"tags\\\":[\\\"test\\\"],\\\"owners\\\":[{\\\"username\\\":\\\"testuser@atic.ar\\\",\\\"name\\\":\\\"Test User\\\",\\\"userId\\\":\\\"649807cb6488dc8ff3c5\\\"}],\\\"readUsers\\\":[],\\\"rfid\\\":\\\"\\\"},{\\\"_id\\\":\\\"649808696bca89048c8f0654\\\",\\\"name\\\":\\\"Bethmannstraße 115\\\",\\\"label\\\":\\\"Behälter 2\\\",\\\"uuid\\\":\\\"e97b24c3-df68-45ef-a7dd-c830205cfae0\\\",\\\"location\\\":\\\"Unbekannt\\\",\\\"tags\\\":[\\\"test\\\"],\\\"owners\\\":[{\\\"username\\\":\\\"testuser@atic.ar\\\",\\\"name\\\":\\\"Test User\\\",\\\"userId\\\":\\\"649807cb6488dc8ff3c5\\\"}],\\\"readUsers\\\":[]}]\"",
The problem is: the response is surrounded with additional "
which are escaped (\"
).

The issue is, in my Flutter code the jsonDecode
function interprets the value of the reponseBody
as a string, instead of an dynamic object.
The value I have copied is directly from Postman to have a more RAW response and out rule package issues from Flutter.

So I created a minimum example:
TypeScript file
type Context = {
req: any;
res: any;
log: (msg: any) => void;
error: (msg: any) => void;
};
class TestModel {
constructor(firstname: string, lastname: string){
this.firstname = firstname;
this.lastname = lastname;
}
firstname: string;
lastname: string;
};
export default async ({ req, res, log, error }: Context) => {
let testObject = new TestModel("John", "Doe");
return res.json(JSON.stringify(testObject));
};
The responseBody
is:
{
...
"responseBody": "\"{\\\"firstname\\\":\\\"John\\\",\\\"lastname\\\":\\\"Doe\\\"}\"",
...
}

Alright I think I understood the mistake. The res.json
function changed in such a way, that the json.stringify()
is done implicitly. So changing ...
res.json(JSON.stringify(testObject));
to ...
res.json(testObject);
should do the trick. 🙂

You shouldn't have even been doing res.json(JSON.stringify(testObject))
in the previous versions 👀

[SOLVED] responseBody does not contain a valid JSON in appwrite function
Recommended threads
- Support for postgreSQL and mongoDb
By when can we expect Appwrite to have support for PostgreSQL and MongoDB, and I hope that along with that, storing and querying of nested objects will also be ...
- Error response from daemon: driver faile...
on endpoint appwrite-traefik (00bbc10e5875d0c367d8975c6abc946a77b7ec201a64a825399add44fb34ebb4): failed to bind port 0.0.0.0:80/tcp: Error starting userland pro...
- API preflight request not working on .f...
When I am calling a function on my APP through the domain is failing. Because the preflight request (OPTIONS HTTP request) times out. this only occurs with fu...
