Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

Prettify JSON

Description
Replace non-formatted JSON value with a pretty-print. Values that cannot be parsed as JSON remain unchanged. Requires the Newtonsoft JSON library.
Language
C#.net
Minimum Version
Created By
pankraty53915
Contributors
-
Date Created
Aug 19, 2019
Date Last Modified
Aug 19, 2019

Macro Code

using Newtonsoft.Json.Linq;

public static class ClipboardFusionHelper
{
	public static string ProcessText(string text)
	{
        string formatted;
		if (TryFormatJson(text, out formatted))
            return formatted;
        
		return text;
	}
	
	private static bool TryFormatJson(string text, out string res)
	{
        try
        {
            res = JToken.Parse(text).ToString();
            return true;
        }
        catch
        {
            res = text;
            return false;
        }
	}
}