-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TryParse method to parse json safely
- Loading branch information
rabdulatif
committed
Oct 6, 2024
1 parent
b3d41e6
commit 9486732
Showing
2 changed files
with
34 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
|
||
namespace MMLib.SwaggerForOcelot.Extensions; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public static class JsonExtensions | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="obj"></param> | ||
Check warning on line 14 in src/MMLib.SwaggerForOcelot/Extensions/JsonExtensions.cs GitHub Actions / build-and-test
|
||
/// <param name="swaggerJson"></param> | ||
/// <returns></returns> | ||
public static bool TryParse(this string swaggerJson, out JObject jObj) | ||
Check warning on line 17 in src/MMLib.SwaggerForOcelot/Extensions/JsonExtensions.cs GitHub Actions / build-and-test
|
||
{ | ||
try | ||
{ | ||
jObj = JObject.Parse(swaggerJson); | ||
return true; | ||
} | ||
catch (Exception ex) | ||
Check warning on line 24 in src/MMLib.SwaggerForOcelot/Extensions/JsonExtensions.cs GitHub Actions / build-and-test
|
||
{ | ||
jObj = null; | ||
return false; | ||
} | ||
} | ||
} |
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