How do I create a json string to publish via MQTT

I try to generate a json string including a sensor value which I then intend to publish via MQTT. I do not figure out how to do it. I feel a bit stupid actually. I would like to do something like this:
sprintf("{ 'temperature' : %s }", sensorvalue)
so that the string is set to e.g. { 'temperature' : 10 }.
I thought BetterLogic could help me but I fail. Is there another app that can help me?

/Niklas