This is the documented behaviour, from man mktemp:
The template may be any file name with some number of `Xs'
appended to it, for example /tmp/temp.XXXXXX
0
chingis
On
Turns out, for whatever reason, macOS version of mktemp supports only trailingXXXXXX for random string, in other words mktemp /tmp/test.XXXX will work but not /tmp/test.XXXX.json
This is the documented behaviour, from man mktemp: