Skip to content

Commit af7e715

Browse files
committed
docs improvement
1 parent b6881b2 commit af7e715

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

.github/workflows/python-app.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
pull_request:
99
branches:
1010
- main
11+
push:
12+
branches:
13+
- main
1114

1215
permissions:
1316
contents: read

DEVELOPMENT.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,10 @@ This is included in `./run_ci_checks.sh`.
200200
## Release Process
201201

202202
1. Update version in `JSONLib/__version__.py`
203-
2. Update CHANGELOG (if maintained)
204-
3. Run full CI checks: `./run_ci_checks.sh`
205-
4. Build package: `./run_build_only.sh`
206-
5. Test on TestPyPI: `./run_testpypi_upload.sh --verify`
207-
6. Publish to PyPI: `twine upload dist/*`
208-
7. Create GitHub release with tag
209-
8. Update documentation site if needed
203+
2. Run full CI checks: `./run_ci_checks.sh`
204+
3. Test on TestPyPI: `./run_testpypi_upload.sh --verify`
205+
4. Publish to PyPI: `twine upload dist/*`
206+
5. Create GitHub release with tag
210207

211208
## Help & Support
212209

JSONLib/jsonlib.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,30 @@ def add_object_to_json(self, json_object, json_path, object_to_add):
108108
109109
Return new json object.
110110
111+
*Behavior:*
112+
113+
- If the json_path exists and points to a dictionary: the object_to_add keys are merged into it
114+
- If the json_path exists and points to a list: the object_to_add is appended to the list
115+
- If the json_path does NOT exist: a new field is created with object_to_add as its value
116+
117+
*Important Note:*
118+
119+
When creating a new field (non-existent path), the entire object_to_add becomes the value.
120+
This means if you add {key1: value1} to $.key1, the result will be {key1: {key1: value1}}.
121+
To avoid this nesting, add to an existing path or use a different field name.
122+
111123
Examples:
124+
| # Adding to existing path (merges keys) |
125+
| ${json}= | Convert String To Json | {"address": {"street": "Main St"}} |
112126
| ${dict}= | Create Dictionary | latitude=13.1234 | longitude=130.1234 |
113-
| ${json}= | Add Object To Json | ${json} | $..address | ${dict} |
127+
| ${json}= | Add Object To Json | ${json} | $..address | ${dict} |
128+
| # Result: {"address": {"street": "Main St", "latitude": "13.1234", "longitude": "130.1234"}} |
129+
| | | | | |
130+
| # Adding to non-existent path (creates new nested object) |
131+
| ${json}= | Convert String To Json | {"name": "John"} |
132+
| ${dict}= | Create Dictionary | city=Bangkok |
133+
| ${json}= | Add Object To Json | ${json} | $.location | ${dict} |
134+
| # Result: {"name": "John", "location": {"city": "Bangkok"}} |
114135
"""
115136
json_path_expr = self._parse(json_path)
116137
json_object_cpy = deepcopy(json_object)

acceptance/JSONLib.robot

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ TestAddJSONObjectByJSONPath
2323
Dictionary Should Contain Key ${json_obj2} friends
2424
Dictionaries Should Be Equal ${json_obj_orignal} ${json_obj_input}
2525

26+
TestAddObjectToNonExistentPath
27+
[Documentation] When adding to a non-existent path, the entire object becomes the value.
28+
... For example, adding {city: Bangkok} to $.location creates {location: {city: Bangkok}}.
29+
... This is the expected behavior - the object is nested under the new field.
30+
${location_data}= Create Dictionary city=Bangkok country=Thailand
31+
${json_with_location}= Add Object To Json ${json_obj_input} $.location ${location_data}
32+
# The entire location_data object becomes the value of the new 'location' field
33+
Dictionary Should Contain Key ${json_with_location} location
34+
Dictionaries Should Be Equal ${json_with_location['location']} ${location_data}
35+
# Verify original data is preserved
36+
Dictionary Should Contain Key ${json_with_location} firstName
37+
2638
TestGetValueByJSONPath
2739
[Documentation] Get some json object using JSONPath
2840
${values}= Get Value From Json ${json_obj_input} $..address.postalCode

docs/index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)