Skip to content

Commit b2b8cbc

Browse files
closes #107 #127 (#129)
* closes #128 * closes #107 #127
1 parent 701ec15 commit b2b8cbc

File tree

5 files changed

+365
-33
lines changed

5 files changed

+365
-33
lines changed

README.md

+113-17
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,57 @@
1919
</div>
2020
</div>
2121

22-
2322
<br/><br/><br/>
2423

25-
## Content
24+
<center style="color:red">
25+
<p style="font-size:20px">We are restricting NPM and Python packages to 2.0.0<br/>
26+
Further versions will only be provided for dotnet and java</p>
27+
</center>
28+
29+
<br/><br/><br/>
2630

27-
- [Import multiple JSON files](#import-multiple-json-files)
28-
- [Deserializing CJSON/JSON string content](#deserializing-cjsonjson-string-content)
29-
- [Calling relative keys using JPATH](#calling-relative-keys-using-jpath)
30-
- [Dynamic variable injection](#dynamic-variable-injection)
31-
- [Single/ Multiple line comments](#single-multiple-line-comments)
32-
- [Removing key](#removing-key)
33-
- [Converting `Class object` to `JSON String`]()
31+
# Content
32+
33+
- [CJSON format Features](#cjson-format-features)
34+
- [Import CJSON/JSON files](#import-multiple-json-files)
35+
- [Referencing another key](#referencing-another-key)
36+
- [Dynamic variable injection](#dynamic-variable-injection)
37+
- [Single injection](#single-injection)
38+
- [Bulk injection](#bulk-injection)
39+
- [Single/ Multiple line comments](#single-multiple-line-comments)
40+
- [CJSON Utility Features](#cjson-utility-features)
41+
- [Deserializing CJSON/JSON string content](#deserializing-cjsonjson-string-content)
42+
- [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)
3454
- [Reference Examples](#examples)
3555

36-
## Features (v2.0.0 or higher)
56+
<br/>
3757

58+
# Features (v2.0.0 or higher)
59+
60+
## CJSON format Features
3861

3962
### Import multiple JSON files
4063

4164
One of the strong feature which we have introduced is importing CJson/Json files in another CJson file.
4265
It works in the similar way, how we import libraries in programming languages. All you need to import it using
4366
`$import "path/to/target/file"` and `deserialize` the file.
4467

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
5069

5170
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.
5271

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.
5473

5574
### Dynamic variable injection
5675

@@ -62,23 +81,70 @@ You can inject a variable dynamically also. Instead of replacing a variable valu
6281
}
6382
```
6483
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.
66104

67105
### Single/ Multiple line comments
68106

69107
CJSON also supports **commented lines** by adding `//` at the start of the line.
70108

71109
**Please note, inline comments are not supported. Contributers create an issue [here](https://github.com/users/SubhenduShekhar/projects/7)**
72110

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+
73129
### Removing key
74130

75131
Any JSON key value pair can be removed by providing its JPath.
76132
Please Note, if you use `remove` before `deserialize` you will receive `UndeserializedCJSON` exception.
77133

78134
This is because, unless the content is deserialized, CJSON engine has not processed the CJSON content.
79135

136+
This function returns deserialized class object post removal.
137+
80138
[Here](https://github.com/SubhenduShekhar/cjson/blob/main/java/Coded-Json/README.md#removing-key) are the examples
81139

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+
82148
### Convert `Class Object` to `JSON String`
83149

84150
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.
87153

88154
[Here](https://github.com/SubhenduShekhar/cjson/blob/main/java/Coded-Json/README.md#removing-key) are the examples
89155

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:
183+
184+
`$.path.to.array[index].variable`
185+
90186
### Examples
91187

92188
- [NPM](https://github.com/SubhenduShekhar/cjson/blob/main/npm/README.md)

0 commit comments

Comments
 (0)