For something you can use in a script transform (though you should probably put this into a project scoped script). Also, make sure you only attempt to use it from Perspective contexts:
from com.inductiveautomation.ignition.common import TypeUtilities
from com.inductiveautomation.perspective.common import PerspectiveModule
gson = PerspectiveModule.createPerspectiveCompatibleGson()
json = TypeUtilities.pyToGson(value, gson)
return "```\n{}\n```".format(gson.toJson(json))
The triple backtick surrounds are to tell the Markdown component that it’s preformatted text, and thus to preserve line breaks and render with a monospaced font - just like code blocks on the forum.