This topic was automatically generated from Slack. You can find the original thread here.
Hi , is there any way to format json string to human-readable format, before sending it in message? I mean, new lines and tabs or spaces, like in feature Format Document in visual studio code.
Yes, you can format a JSON string to a human-readable format using JSON.stringify() with additional arguments for spacing. Here’s an example: export default defineComponent({ async run({ steps, $ }) { const jsonString = '{"key1":"value1","key2":"value2"}'; const formattedJson = JSON.stringify(JSON.parse(jsonString), null, 2); return formattedJson; }, }); In this example, JSON.parse(jsonString) converts the JSON string to a JavaScript object, and then JSON.stringify() is used with the arguments null and 2 to format the object with 2 spaces of indentation. The resulting formattedJson will be a human-readable JSON string.