You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- [Deserialize as class object](#deserialize-as-class-object)
43
+
- [Deserialize as string](#deserialize-as-string)
44
+
-[Remove](#removing-key)
45
+
-[Single removal](#single-removal)
46
+
-[Bulk removal](#bulk-removal)
47
+
-[Converting `Class object` to `JSON String`](#convert-class-object-to-json-string)
48
+
-[Parse data](#parse-data)
49
+
-[Parse](#parse)
50
+
-[Get all possible keys](#get-all-possible-keys)
51
+
-[Get all possible values](#get-all-possible-values)
52
+
-[Validate JSON](#validate-json)
53
+
-[Writing JPath](#writing-jpath)
34
54
-[Reference Examples](#examples)
35
55
36
-
## Features (v2.0.0 or higher)
56
+
<br/>
37
57
58
+
# Features (v2.0.0 or higher)
59
+
60
+
## CJSON format Features
38
61
39
62
### Import multiple JSON files
40
63
41
64
One of the strong feature which we have introduced is importing CJson/Json files in another CJson file.
42
65
It works in the similar way, how we import libraries in programming languages. All you need to import it using
43
66
`$import "path/to/target/file"` and `deserialize` the file.
44
67
45
-
### Deserializing CJSON/JSON string content
46
-
47
-
Parsing of CJSON string content is also possible now. You can create CJSON object with a second parameter(specific to language). For language specific details, refer below.
48
-
49
-
### Calling relative keys using JPATH
68
+
### Referencing another key
50
69
51
70
Unlike XPATH for XML files, we have JPATH for JSON files. But as the drawback of plain data files, we cannot refer any variable inside a json object to another variable. This feature is useful when you have to duplicate the json key, but the value will be pulled from another variable which is already present in the json file.
52
71
53
-
You can also refer to a variable which will be loaded after importing the file.
72
+
You can also refer to a variable which will be loaded after importing the file.
54
73
55
74
### Dynamic variable injection
56
75
@@ -62,23 +81,70 @@ You can inject a variable dynamically also. Instead of replacing a variable valu
62
81
}
63
82
```
64
83
Now create a `HashMap` with key as `<id>` and store relevant value in it.
65
-
While invoking `inject` function, pass the HashMap as the second parameter.
84
+
While invoking `inject` function, pass the HashMap as the second parameter.
85
+
86
+
Injection can be performed single or bulk. Lets look at each one below:
87
+
88
+
#### Single injection
89
+
90
+
Single injection can be performed by providing key and value to the `inject()`.
91
+
92
+
`inject(String key, Object value)`
93
+
94
+
This function returns `deserialized` class object.
95
+
96
+
#### Bulk injection
97
+
98
+
Bulk injection can be performed by storing the injection data in `Dictionary` or `HashMap`
99
+
where key is the `key` where injection need to be performed and `value` is the value.
100
+
101
+
`inject(HashMap<String, Object>)`
102
+
103
+
This function returns `deserialized` class object.
66
104
67
105
### Single/ Multiple line comments
68
106
69
107
CJSON also supports **commented lines** by adding `//` at the start of the line.
70
108
71
109
**Please note, inline comments are not supported. Contributers create an issue [here](https://github.com/users/SubhenduShekhar/projects/7)**
72
110
111
+
## CJSON Utility Features
112
+
113
+
### Deserializing CJSON/JSON string content
114
+
115
+
Parsing of CJSON string content is also possible now. You can create CJSON object with a second parameter(specific to language). For language specific details, refer below.
116
+
117
+
#### Deserialize as class object
118
+
119
+
`deserialize` is a function where CJSON content is compiled and converted into equivalent JSON content.
120
+
Now, users can consume this content as a deserailized class object like any other parser works.
121
+
122
+
Refer to [example](#examples) for language specific syntax.
123
+
124
+
#### Deserialize as string
125
+
126
+
User can consume converted JSON content to `String` content too. Every language has a function `deserializeAsString()`
127
+
which converts compiles and converts CJSON to JSON content and returns JSON content in string format
128
+
73
129
### Removing key
74
130
75
131
Any JSON key value pair can be removed by providing its JPath.
76
132
Please Note, if you use `remove` before `deserialize` you will receive `UndeserializedCJSON` exception.
77
133
78
134
This is because, unless the content is deserialized, CJSON engine has not processed the CJSON content.
79
135
136
+
This function returns deserialized class object post removal.
137
+
80
138
[Here](https://github.com/SubhenduShekhar/cjson/blob/main/java/Coded-Json/README.md#removing-key) are the examples
81
139
140
+
#### Single removal
141
+
142
+
Single removal can be performed by simply providing the JPath as parameters.
143
+
144
+
#### Bulk removal
145
+
146
+
Bulk removal accepts `List<String> JPaths` to perform removal.
147
+
82
148
### Convert `Class Object` to `JSON String`
83
149
84
150
Any Java object can be converted to json string by using `toString()` function.
@@ -87,6 +153,36 @@ It accepts pure java object and returns JSON in string.
87
153
88
154
[Here](https://github.com/SubhenduShekhar/cjson/blob/main/java/Coded-Json/README.md#removing-key) are the examples
89
155
156
+
### Parse data
157
+
158
+
#### Parse
159
+
160
+
This function finds the value of the provided JPath as parameter. This function returns `Object` type data.
161
+
So a type cast will be required to unlock native functions.
162
+
163
+
#### Get all possible keys
164
+
165
+
Returns all possible `JPaths` inside JSON.
166
+
167
+
#### Get all possible values
168
+
169
+
Returns all values to all possible `JPaths` inside JSON. Before executing this function, you need call for getting all possible keys function.
170
+
171
+
### Validate JSON
172
+
173
+
This function validates whether the provided string is JSON content or not.
174
+
175
+
### Writing JPath
176
+
177
+
Unline XPath in xml format, JSON has JPath format. THe difference is, instead of `//` or `/`, JPath starts with `$.`
178
+
Below is an example:
179
+
180
+
`$.path.to.variables`
181
+
182
+
If any array is encountered, below is the way index is provided:
0 commit comments