https://github.com/mrkresnofatih/khonsu.parseablejsonobjectbuilder
Read-Json-Parse-To-Class-Object Utility π¦π¦π¦πΌπ±
https://github.com/mrkresnofatih/khonsu.parseablejsonobjectbuilder
file json parser
Last synced: 3 months ago
JSON representation
Read-Json-Parse-To-Class-Object Utility π¦π¦π¦πΌπ±
- Host: GitHub
- URL: https://github.com/mrkresnofatih/khonsu.parseablejsonobjectbuilder
- Owner: mrkresnofatih
- Created: 2022-05-07T12:48:38.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-05-07T12:49:52.000Z (about 4 years ago)
- Last Synced: 2025-10-27T21:52:59.158Z (8 months ago)
- Topics: file, json, parser
- Language: C#
- Homepage: https://www.nuget.org/packages/Khonsu.ParseableJsonObjectBuilder/
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
ο»Ώ# Khonsu.ParseableJsonObjectBuilder
A simple json-to-class-object parser utility. A simple usage case is displayed below.
Target Json File:
```json
{
"Policy": "Basic Permissions",
"Version": "v1.3.12",
"GrantedPermissions": {
"Authentication": [
"APP.AUTH.LOGIN",
"APP.AUTH.SIGNUP",
"APP.AUTH.LOGOUT"
],
"Management": [
"APP.MNG.CREATE_IAM",
"APP.MNG.REVOKE_IAM",
"APP.MNG.UPDATE_IAM"
]
},
"PolicyActive": true,
"CreatedAt": 2341209
}
```
Basic Permission Class is the example class object.
```c#
public class BasicPermission
{
public string Policy { get; set; }
public string Version { get; set; }
public Dictionary> GrantedPermissions { get; set; }
public bool PolicyActive { get; set; }
public long CreatedAt { get; set; }
public void PrintSelf()
{
Console.WriteLine($"Policy: {Policy}");
Console.WriteLine($"Version: {Version}");
foreach (var grantedPermissionsKey in GrantedPermissions.Keys)
{
Console.Write(grantedPermissionsKey + ": [");
foreach (var value in GrantedPermissions[grantedPermissionsKey])
{
Console.Write(value + ",");
}
Console.WriteLine("]");
}
Console.WriteLine($"PolicyActive: {PolicyActive}");
Console.WriteLine($"CreatedAt: {CreatedAt}");
}
}
```
We parse the json to object as follows.
```c#
class Program
{
static void Main(string[] args)
{
var basicPermission = new ParseableJsonObjectBuilder()
.SetJsonPath("Configurations/BasicPermissions.json") // Path from the root dir of project
.Build();
basicPermission.PrintSelf();
// Policy: Basic Permissions
// Version: v1.3.12
// Authentication: [APP.AUTH.LOGIN,APP.AUTH.SIGNUP,APP.AUTH.LOGOUT,]
// Management: [APP.MNG.CREATE_IAM,APP.MNG.REVOKE_IAM,APP.MNG.UPDATE_IAM,]
// PolicyActive: True
// CreatedAt: 2341209
}
}
```