docker and format json

I’m trying to get usable json from the docker cli, however it seems it will only produce json for individual items, and not the complete result, as a whole.

For example, running docker container ls -a --format="{{ json .Names }}" produces:


The above is not json.

How can I produce a result that is, ideally, a json array?

Source: StackOverflow