How to speed up converting Dict to Json?

However, when the json_payload contains a field that is the base64 encoding of an image (around 2MB in size), the call to JSON.json(payload) takes a very long time to complete.

Can you provide a reproducible example with data? What do you consider a “very long time”?

I tried running JSON.json on a Dict containing a 2MB string, and it takes 20ms.

julia> using JSON, Random, BenchmarkTools

julia> payload = Dict("foo" => Random.randstring(2^21)); # 2MB string

julia> @btime JSON.json($payload);
  21.234 ms (35 allocations: 4.44 MiB)

It’s going to be hard for anyone to help you without more information. Something like the above, where you provide code to generate a Dict containing random data, would be easiest to reproduce.