Skip to content

Commit 3eaa756

Browse files
closes #24 (#62)
1 parent 7ea6326 commit 3eaa756

File tree

7 files changed

+110
-12
lines changed

7 files changed

+110
-12
lines changed

.github/workflows/java-tests.yml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
push:
77
branches:
88
- main
9+
paths:
10+
- java/**
911

1012
jobs:
1113

.github/workflows/npm-tests.yml

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
push:
77
branches:
88
- main
9+
paths:
10+
- npm/**
11+
- tests/npm/**
912

1013
jobs:
1114

.github/workflows/python-tests.yml

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
push:
77
branches:
88
- main
9+
paths:
10+
- python
11+
- tests/python/**
912

1013
jobs:
1114

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ One of the strong feature which we have introduced is importing CJson/Json files
2929
It works in the similar way, how we import libraries in programming languages. All you need to import it using
3030
`$import "path/to/target/file"` and `deserialize` the file.
3131

32+
### Deserializing CJSON/JSON string content
33+
34+
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.
35+
3236
### Calling relative keys using JPATH
3337

3438
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.
3539

3640
You can also refer to a variable which will be loaded after importing the file.
3741

38-
### Dynamic variable injection <b> (JAVA Only) </b>
39-
40-
***This feature is only available in JAVA and for pure values***
42+
### Dynamic variable injection
4143

4244
You can inject a variable dynamically also. Instead of replacing a variable value by parsing as `gson` object, put a key in format `<keyToBeReplaced>` like below:
4345

npm/README.md

+44-9
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,8 @@ Below example shows `color` variable is calling data from `fruit` variable
8080
#### Code
8181

8282
```
83-
<<<<<<< HEAD
84-
import Cjson from "coded-json";
85-
var cjson: Cjson = new Cjson("path/to/file.cjson");
86-
=======
8783
import { Cjson } from 'coded-json';
8884
var cjson = new Cjson(file/path/to/file.cjson);
89-
>>>>>>> 6a7c309a47cd4870f80797b696a59e2f93314b87
9085
var b = cjson.deserialize();
9186
```
9287

@@ -102,11 +97,51 @@ Below example shows `color` variable is calling data from `fruit` variable
10297
}
10398
```
10499

105-
### Single/ Multiple line comments
106-
<<<<<<< HEAD
100+
### Dynamic variable injection
101+
102+
#### file.cjson
107103

108-
=======
109-
>>>>>>> 6a7c309a47cd4870f80797b696a59e2f93314b87
104+
```
105+
{
106+
"target": {
107+
"types": "asd",
108+
"fruit": <fruit>,
109+
"quantity": <quantity>,
110+
},
111+
"jsonInjection": <jsonTypeData>
112+
}
113+
```
114+
115+
#### Code
116+
117+
```
118+
var cjson = new Cjson(file/path/to/file.cjson);
119+
var injectObj = {
120+
fruit: "apple",
121+
quantity: 1,
122+
jsonTypeData: {
123+
injectedData: "jsonInjectionValue"
124+
}
125+
};
126+
var deserializedVal = cjson.inject(injectObj);
127+
```
128+
129+
#### Output
130+
131+
```
132+
{
133+
"target": {
134+
"types": "asd",
135+
"fruit": "apple,
136+
"quantity": 1,
137+
},
138+
"jsonInjection": {
139+
injectedData: "jsonInjectionValue"
140+
}
141+
}
142+
```
143+
144+
### Single/ Multiple line comments
110145

111146
For single line comments, use `//`
112147

python/README.md

+52
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,58 @@ Below example shows `color` variable is calling data from `fruit` variable
9797
}
9898
```
9999

100+
### Dynamic variable injection
101+
102+
#### file.cjson
103+
104+
```
105+
{
106+
"target": {
107+
"types": "asd",
108+
"fruit": <fruit>,
109+
"quantity": <quantity>,
110+
},
111+
"jsonInjection": <jsonTypeData>
112+
}
113+
```
114+
115+
#### Code
116+
117+
```
118+
cjson = Cjson(variable_injection)
119+
120+
injec_data = {
121+
"fruit": "apple",
122+
"quantity": 1,
123+
"jsonTypeData": {
124+
"secondaryData": {
125+
"type": "fruit",
126+
"seeds": "yes"
127+
}
128+
}
129+
}
130+
131+
data = cjson.inject(injecting_obj=injec_data)
132+
```
133+
134+
#### Output
135+
136+
```
137+
{
138+
"target": {
139+
"types": "asd",
140+
"fruit": "apple,
141+
"quantity": 1,
142+
},
143+
"jsonInjection": {
144+
"secondaryData": {
145+
"type": "fruit",
146+
"seeds": "yes"
147+
}
148+
}
149+
}
150+
```
151+
100152
### Single/ Multiple line comments
101153

102154

tests/python/cjson_tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def test5(self):
8383
self.assertEqual(cjson.json.parse("target.quantity"), injec_data["quantity"])
8484
self.assertEqual(cjson.json.parse("jsonInjection.secondaryData.type"), injec_data["jsonTypeData"]["secondaryData"]["type"])
8585

86+
add_resut(Result.Pass, "I should be able to inject data using inject()")
8687

8788
class JSONTests(unittest.TestCase):
8889
def test1(self):

0 commit comments

Comments
 (0)