[SOLVED] jsonEncode vs JSON.stringify - why does dart escape strings?

I’ve come across an issue where my API request bodies are unexpectedly being escaped.

e.g.

jsonEncode( {
        "header": "test \n string",
});

--> '{"header":"test \\n string"}'

In javascript, JSON.stringify does not escape the \n.

I’m confused why dart is escaping strings by default, and can it be turned off?

2 Likes

@joshburton I think you solved this one?

@joshburton told on Bluesky that he found the bug in his code :person_shrugging: