-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeParser.cs
More file actions
39 lines (36 loc) · 1.22 KB
/
NodeParser.cs
File metadata and controls
39 lines (36 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Text.Json;
using System.Text.Json.Serialization;
using Contentstack.Utils.Interfaces;
using Contentstack.Utils.Models;
using Contentstack.Utils.Tests.Constants;
using Contentstack.Utils.Tests.Mocks;
namespace Contentstack.Utils.Tests.Helpers
{
public class NodeParser
{
public static Node parse(string jsonNode)
{
// Remove trailing commas before closing brackets/braces
string cleanedJson = System.Text.RegularExpressions.Regex.Replace(
jsonNode,
@",(\s*[}\]])",
"$1"
);
return JsonSerializer.Deserialize<Node>(cleanedJson);
}
}
public class GQLParser
{
public static GQLModel<T> parse<T>(string jsonNode, string embedConnection = null) where T: IEmbeddedObject
{
var data = JsonToHtmlConstants.KGQLModel(jsonNode, embedConnection);
// Remove trailing commas before closing brackets/braces
string cleanedJson = System.Text.RegularExpressions.Regex.Replace(
data,
@",(\s*[}\]])",
"$1"
);
return JsonSerializer.Deserialize<GQLModel<T>>(cleanedJson);
}
}
}