Skip to content

Commit bdca780

Browse files
authored
Update REFERENCE.md
1 parent bab6f04 commit bdca780

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

REFERENCE.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
# Skybrud.Essentials
22

3+
## JSON
4+
5+
### JsonUtils
6+
7+
In Skybrud.Essentials, the static `JsonUtils` class comes with a number of helpful utility methods and other functionality for working with JSON (and [JSON.net](https://www.newtonsoft.com/json) in particular).
8+
9+
For instance, you can parse or load JSON objects using the `JsonUtils.ParseJsonObject` and `JsonUtils.LoadJsonObject` methods respectively:
10+
11+
```c#
12+
@using Skybrud.Essentials.Json
13+
@{
14+
15+
// Parse a JSON object from a string
16+
JObject json1 = JsonUtils.Parse("{\"hello\":\"world\"}");
17+
18+
// Load a JSON object from a file on disk
19+
JObject json2 = JsonUtils.Load("C:/path/to/file.json");
20+
21+
}
22+
```
23+
24+
The `JsonUtils.Parse` method does somewhat the same as `JObject.Parse`, but JSON.net's default settings will deserialize string properties that look like dates to actual instances of `DateTime` - which when serialized back to a JSON string might not look like the original string value. The `JsonUtils.Parse` will make sure that these values will stay as strings so the format wont change.
25+
26+
The `JsonUtils.Load` will read from the file so you don't have to do this your self. The contents of the file is then passed on to the `JsonUtils.Parse` method, giving the same result as described above.
27+
28+
### Converters
29+
30+
Skybrud.Essentials also comes with a number of JSON converters. For instance, there are a number of ways to serialize an enum value. Default in JSON.net is to use the enum values numeric value, but this may not always be the desired result.
31+
32+
So, if you wish to store your enum values using camel case (eg. `camelCase`), you can use the `EnumCamelCaseConverter` on your property or enum class. In a similar way, you can convert to Pascal case (eg. `PascalCase`) using `EnumPascalCaseConverter`, and to lower case (eg. `lowercase`) using `EnumLowerCaseConverter`.
33+
34+
35+
36+
37+
38+
39+
40+
41+
342
## Time
443

544
### EssentialsDateTime

0 commit comments

Comments
 (0)