-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #162 better handling when a string "looks" like JSON
- Loading branch information
Kevin Jump
committed
Oct 1, 2020
1 parent
0373a9b
commit 7433a1a
Showing
5 changed files
with
50 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
| ||
using Newtonsoft.Json.Linq; | ||
|
||
using Umbraco.Core; | ||
|
||
namespace uSync8.Core | ||
{ | ||
public static class JsonExtensions | ||
{ | ||
/// <summary> | ||
/// get a JToken value of a string. | ||
/// </summary> | ||
/// <remarks> | ||
/// if the string is valid JSON then you will get a parsed | ||
/// version of the json. | ||
/// | ||
/// if it isn't then you just get the string value (which will cast | ||
/// automatically to JToken when you need it). | ||
/// </remarks> | ||
public static JToken GetJsonTokenValue(this string value) | ||
{ | ||
if (value.DetectIsJson()) | ||
{ | ||
try | ||
{ | ||
return JToken.Parse(value); | ||
} | ||
catch | ||
{ | ||
// error parsing, so it's not actually json | ||
// it just might look like it a bit. | ||
return value; | ||
} | ||
} | ||
|
||
return value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters