How can I keep leading and trailing spaces in a parsed string?

You can only use the json_... functions to navigate when in JSON mode, so no gotochar for you there.

See How to Say to output without trimming whitespace? for a similar topic which describes the trimming of whitespace you're observing.