JSON projection leading to invalid json

Using community 2025.07.1

I have an issue regarding the custom JSON I generate from my cypher.
My query works, here is the RETURN part (from a string template where I replace the $var$)

 RETURN {
  results: collect({
    synset: s.synset,
    pos: s.pos,
     eng: lemmas_eng,
     lemmas: lemmas_dest,
     definitions: definitions
   }),
   query: {src: "$LANG1$", dest: "$LANG2$", query: "$LEMMA$"}
}


[{results: [{synset: "02959942-n", definitions: [{lang: "ron", definition: "Vehicul ușor, asemănător cu un vagonet, acționat cu mâna, cu pedale sau cu un motor, care servește la transporturi ușoare pe o linie ferată."}], pos: "n", lemmas: ["drezină"], eng: ["car", "railroad car", "railcar", "railway car"]}, {synset: "03895866-n", definitions: [{lang: "ron", definition: "vagon care servește la transportul călătorilor"}], pos: "n", lemmas: ["vagondecălători"], eng: ["carriage", "coach", "passenger car"]}, {synset: "02958343-n", definitions: [{lang: "ron", definition: "Vehicul cu patru (rar trei, șase) roți pneumatice, mișcat de un motor cu explozie internă, cu aburi, cu electricitate sau aer comprimat"}], pos: "n", lemmas: ["mașină", "autovehicul", "automobil"], eng: ["automobile", "motorcar", "auto", "machine", "car"]}], query: {dest: "ron", src: "spa", query: "coche"}}]

should be [{“results”: …… and so on.

Unfortunately the JSON is invalid because all keys should be inside double quotes too.
I had forgotten about that.

If I go the simple route and add double quotes in my cypher then my quarkus endpoint code gives me a 500 error but does not give more explanation.
I checked and it makes the cypher invalid. Single quotes do not do the job either.
Escaping the quotes ? Nah does work either.

I presume there is some configuration possible for json projection however, I did not find it yet.

Therefore I’d like your help

Thank you for your time

The success came from using Jackson’s objectmapper.

Overall, considering all the async call code, the code seems over engineered considering I just get some json as text that is already (half) prepared at query level. ¯\_(ツ)_/¯

Key instruction to get validatable json is

String jsonResult = objectMapper.writeValueAsString(record.get(0).asMap());

You could try APOC to convert you cypher map to a json.