Generally I have the most success with json like that if I use single
quotes outside the actual json and double quotes inside.
Something like this:
JSONSTRING='{"mykey":"myval"}'
So to get:
grains:
roles: test
I'd do:
JSONSTRING='{"grains":{"roles":"test"}}'
There's a bunch of great yaml to json and json to yaml converters
online to double check.