csonpath 0.0.1__tar.gz → 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- csonpath-0.0.2/PKG-INFO +126 -0
- {csonpath-0.0.1 → csonpath-0.0.2}/README.md +13 -2
- csonpath-0.0.2/csonpath.egg-info/PKG-INFO +126 -0
- {csonpath-0.0.1 → csonpath-0.0.2}/pyproject.toml +2 -1
- csonpath-0.0.1/PKG-INFO +0 -7
- csonpath-0.0.1/csonpath.egg-info/PKG-INFO +0 -7
- {csonpath-0.0.1 → csonpath-0.0.2}/LICENSE +0 -0
- {csonpath-0.0.1 → csonpath-0.0.2}/MANIFEST.in +0 -0
- {csonpath-0.0.1 → csonpath-0.0.2}/csonpath.egg-info/SOURCES.txt +0 -0
- {csonpath-0.0.1 → csonpath-0.0.2}/csonpath.egg-info/dependency_links.txt +0 -0
- {csonpath-0.0.1 → csonpath-0.0.2}/csonpath.egg-info/requires.txt +0 -0
- {csonpath-0.0.1 → csonpath-0.0.2}/csonpath.egg-info/top_level.txt +0 -0
- {csonpath-0.0.1 → csonpath-0.0.2}/csonpath.h +0 -0
- {csonpath-0.0.1 → csonpath-0.0.2}/csonpath_do.h +0 -0
- {csonpath-0.0.1 → csonpath-0.0.2}/csonpath_python.c +0 -0
- {csonpath-0.0.1 → csonpath-0.0.2}/setup.cfg +0 -0
csonpath-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: csonpath
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Description-Content-Type: text/markdown
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Provides-Extra: dev
|
|
7
|
+
Requires-Dist: pytest>=8.3.5; extra == "dev"
|
|
8
|
+
Dynamic: license-file
|
|
9
|
+
|
|
10
|
+
# csonpath
|
|
11
|
+
|
|
12
|
+
> that's not my path, that's not your path, but csonpath
|
|
13
|
+
|
|
14
|
+
[](https://docs.outscale.com/en/userguide/Open-Source-Projects.html)
|
|
15
|
+
|
|
16
|
+
**csonpath** is a partial [JSONPath](https://goessner.net/articles/JsonPath/) implementation in C, with Python bindings. It allows you to query, update, and remove data from JSON objects using path expressions.
|
|
17
|
+
|
|
18
|
+
## 🌐 Links
|
|
19
|
+
|
|
20
|
+
- Project website: https://github.com/outscale/csonpath
|
|
21
|
+
- Join our community on [Discord](https://discord.gg/HUVtY5gT6s)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## 📄 Table of Contents
|
|
25
|
+
|
|
26
|
+
- [Overview](#-overview)
|
|
27
|
+
- [Requirements](#-requirements)
|
|
28
|
+
- [Installation](#-installation)
|
|
29
|
+
- [Configuration](#-configuration)
|
|
30
|
+
- [Usage](#-usage)
|
|
31
|
+
- [Examples](#-examples)
|
|
32
|
+
- [License](#-license)
|
|
33
|
+
- [Contributing](#-contributing)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## 🚀 Features
|
|
37
|
+
|
|
38
|
+
- **Find First**: Retrieve the first value matching a path.
|
|
39
|
+
- **Find All**: Retrieve all values matching a path.
|
|
40
|
+
- **Update or Create**: Update values or create new ones according to the path.
|
|
41
|
+
- **Remove**: Remove values matching a path.
|
|
42
|
+
- **Update or Create Callback**: Update values or create new ones according to the path, using a user-define callback.
|
|
43
|
+
- **Callback**: Call a callback according to the path.
|
|
44
|
+
- **Supports both C (using json-c) and Python objects.**
|
|
45
|
+
|
|
46
|
+
## ✅ Getting Started
|
|
47
|
+
|
|
48
|
+
### Prerequisites
|
|
49
|
+
|
|
50
|
+
- C compiler (gcc/clang)
|
|
51
|
+
- [json-c](https://github.com/json-c/json-c) library for C usage
|
|
52
|
+
- Python 3.x (for Python bindings)
|
|
53
|
+
|
|
54
|
+
### Build
|
|
55
|
+
|
|
56
|
+
To build the C tests and examples:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
make
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Usage (json-c)
|
|
63
|
+
|
|
64
|
+
See examples in [`tests/json-c/get-a.c`](tests/json-c/get-a.c):
|
|
65
|
+
|
|
66
|
+
```c
|
|
67
|
+
#include "csonpath_json-c.h"
|
|
68
|
+
|
|
69
|
+
const char *json_str = "{ \"a\": \"value\", \"array\": [1,2,3] }";
|
|
70
|
+
struct csonpath p;
|
|
71
|
+
struct json_object *jobj = json_tokener_parse(json_str);
|
|
72
|
+
struct json_object *ret;
|
|
73
|
+
|
|
74
|
+
csonpath_init(&p, "$.a");
|
|
75
|
+
ret = csonpath_find_first(&p, jobj);
|
|
76
|
+
// ret now points to "value"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Usage (Python)
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import csonpath
|
|
83
|
+
|
|
84
|
+
d = { "a": "value", "array": [1,2,3] }
|
|
85
|
+
o = csonpath.CsonPath("$.a")
|
|
86
|
+
print(o.find_first(d)) # Output: "value"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Avaible methodes:
|
|
90
|
+
- `CsonPath(path)`: create a new csonpath object.
|
|
91
|
+
- `OBJ.find_first(self, json)`: take a json, return first found occurrence.
|
|
92
|
+
- `OBJ.find_all(self, json)`: take a json, return all found occurrence in a list.
|
|
93
|
+
- `OBJ.remove(self, json)`: take a json, remove all found occurrence from it.
|
|
94
|
+
- `OBJ.update_or_create(self, json, value)`: take a json, replace all found occurrence from it, by the value, if doesn't found something, create it.
|
|
95
|
+
- `OBJ.update_or_create_callback(self, json, callback, callback_data)`: take a json, if it doesn't find a parent object, create it, then it calls a callback.
|
|
96
|
+
- `OBJ.callback(self, json, callback, callback_data)`: take a json, call a callback, an all occurrence.
|
|
97
|
+
|
|
98
|
+
`callback` is a function that take 4 arguments: `parent`, `idx`, `cur_value` and `callback_data`
|
|
99
|
+
|
|
100
|
+
Check [`tests`](tests/python/) for more examples
|
|
101
|
+
|
|
102
|
+
### Backends and Direct Usage
|
|
103
|
+
|
|
104
|
+
csonpath is inspired by JSONPath, but is designed to be backend-agnostic: it can work with any C library or environment that manipulates array, object, and scalar types—not just JSON. Out of the box, backends for Python and json-c are provided, but you can create your own backend for other formats such as YAML, or any custom data structure.
|
|
105
|
+
|
|
106
|
+
To use csonpath with a different data type or library, simply define the required macros and types in a header file (similar to `csonpath_json-c.h` or `csonpath_python.c`), then include your backend header before `csonpath.h`. This approach allows you to adapt csonpath for manipulating data in any format that supports array/object semantics, giving you full flexibility beyond just JSON.
|
|
107
|
+
|
|
108
|
+
## Directory Structure
|
|
109
|
+
|
|
110
|
+
- `csonpath.h`, `csonpath_do.h` - Main implementation files
|
|
111
|
+
- `csonpath_json-c.h` - Json-C implementation, use it by including "csonpath_json-c.h" directly in your source
|
|
112
|
+
- `csonpath_python.c` - python implementation, use it like a python lib (so `pip install .`)
|
|
113
|
+
- `tests/` - Contains tests
|
|
114
|
+
- `bench//` - Some benchmarks
|
|
115
|
+
|
|
116
|
+
## 🤝 Contributing
|
|
117
|
+
|
|
118
|
+
We welcome contributions!
|
|
119
|
+
|
|
120
|
+
Please read our [Contributing Guidelines](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) before submitting a pull request.
|
|
121
|
+
|
|
122
|
+
Feel free to open issues or pull requests!
|
|
123
|
+
|
|
124
|
+
## 📜 License
|
|
125
|
+
BSD 3-Clause. See [LICENSE](LICENSE).
|
|
126
|
+
|
|
@@ -69,8 +69,6 @@ ret = csonpath_find_first(&p, jobj);
|
|
|
69
69
|
|
|
70
70
|
### Usage (Python)
|
|
71
71
|
|
|
72
|
-
Check [`dump-test.py`](dump-test.py) for examples:
|
|
73
|
-
|
|
74
72
|
```python
|
|
75
73
|
import csonpath
|
|
76
74
|
|
|
@@ -79,6 +77,19 @@ o = csonpath.CsonPath("$.a")
|
|
|
79
77
|
print(o.find_first(d)) # Output: "value"
|
|
80
78
|
```
|
|
81
79
|
|
|
80
|
+
#### Avaible methodes:
|
|
81
|
+
- `CsonPath(path)`: create a new csonpath object.
|
|
82
|
+
- `OBJ.find_first(self, json)`: take a json, return first found occurrence.
|
|
83
|
+
- `OBJ.find_all(self, json)`: take a json, return all found occurrence in a list.
|
|
84
|
+
- `OBJ.remove(self, json)`: take a json, remove all found occurrence from it.
|
|
85
|
+
- `OBJ.update_or_create(self, json, value)`: take a json, replace all found occurrence from it, by the value, if doesn't found something, create it.
|
|
86
|
+
- `OBJ.update_or_create_callback(self, json, callback, callback_data)`: take a json, if it doesn't find a parent object, create it, then it calls a callback.
|
|
87
|
+
- `OBJ.callback(self, json, callback, callback_data)`: take a json, call a callback, an all occurrence.
|
|
88
|
+
|
|
89
|
+
`callback` is a function that take 4 arguments: `parent`, `idx`, `cur_value` and `callback_data`
|
|
90
|
+
|
|
91
|
+
Check [`tests`](tests/python/) for more examples
|
|
92
|
+
|
|
82
93
|
### Backends and Direct Usage
|
|
83
94
|
|
|
84
95
|
csonpath is inspired by JSONPath, but is designed to be backend-agnostic: it can work with any C library or environment that manipulates array, object, and scalar types—not just JSON. Out of the box, backends for Python and json-c are provided, but you can create your own backend for other formats such as YAML, or any custom data structure.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: csonpath
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Description-Content-Type: text/markdown
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Provides-Extra: dev
|
|
7
|
+
Requires-Dist: pytest>=8.3.5; extra == "dev"
|
|
8
|
+
Dynamic: license-file
|
|
9
|
+
|
|
10
|
+
# csonpath
|
|
11
|
+
|
|
12
|
+
> that's not my path, that's not your path, but csonpath
|
|
13
|
+
|
|
14
|
+
[](https://docs.outscale.com/en/userguide/Open-Source-Projects.html)
|
|
15
|
+
|
|
16
|
+
**csonpath** is a partial [JSONPath](https://goessner.net/articles/JsonPath/) implementation in C, with Python bindings. It allows you to query, update, and remove data from JSON objects using path expressions.
|
|
17
|
+
|
|
18
|
+
## 🌐 Links
|
|
19
|
+
|
|
20
|
+
- Project website: https://github.com/outscale/csonpath
|
|
21
|
+
- Join our community on [Discord](https://discord.gg/HUVtY5gT6s)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## 📄 Table of Contents
|
|
25
|
+
|
|
26
|
+
- [Overview](#-overview)
|
|
27
|
+
- [Requirements](#-requirements)
|
|
28
|
+
- [Installation](#-installation)
|
|
29
|
+
- [Configuration](#-configuration)
|
|
30
|
+
- [Usage](#-usage)
|
|
31
|
+
- [Examples](#-examples)
|
|
32
|
+
- [License](#-license)
|
|
33
|
+
- [Contributing](#-contributing)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## 🚀 Features
|
|
37
|
+
|
|
38
|
+
- **Find First**: Retrieve the first value matching a path.
|
|
39
|
+
- **Find All**: Retrieve all values matching a path.
|
|
40
|
+
- **Update or Create**: Update values or create new ones according to the path.
|
|
41
|
+
- **Remove**: Remove values matching a path.
|
|
42
|
+
- **Update or Create Callback**: Update values or create new ones according to the path, using a user-define callback.
|
|
43
|
+
- **Callback**: Call a callback according to the path.
|
|
44
|
+
- **Supports both C (using json-c) and Python objects.**
|
|
45
|
+
|
|
46
|
+
## ✅ Getting Started
|
|
47
|
+
|
|
48
|
+
### Prerequisites
|
|
49
|
+
|
|
50
|
+
- C compiler (gcc/clang)
|
|
51
|
+
- [json-c](https://github.com/json-c/json-c) library for C usage
|
|
52
|
+
- Python 3.x (for Python bindings)
|
|
53
|
+
|
|
54
|
+
### Build
|
|
55
|
+
|
|
56
|
+
To build the C tests and examples:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
make
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Usage (json-c)
|
|
63
|
+
|
|
64
|
+
See examples in [`tests/json-c/get-a.c`](tests/json-c/get-a.c):
|
|
65
|
+
|
|
66
|
+
```c
|
|
67
|
+
#include "csonpath_json-c.h"
|
|
68
|
+
|
|
69
|
+
const char *json_str = "{ \"a\": \"value\", \"array\": [1,2,3] }";
|
|
70
|
+
struct csonpath p;
|
|
71
|
+
struct json_object *jobj = json_tokener_parse(json_str);
|
|
72
|
+
struct json_object *ret;
|
|
73
|
+
|
|
74
|
+
csonpath_init(&p, "$.a");
|
|
75
|
+
ret = csonpath_find_first(&p, jobj);
|
|
76
|
+
// ret now points to "value"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Usage (Python)
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import csonpath
|
|
83
|
+
|
|
84
|
+
d = { "a": "value", "array": [1,2,3] }
|
|
85
|
+
o = csonpath.CsonPath("$.a")
|
|
86
|
+
print(o.find_first(d)) # Output: "value"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Avaible methodes:
|
|
90
|
+
- `CsonPath(path)`: create a new csonpath object.
|
|
91
|
+
- `OBJ.find_first(self, json)`: take a json, return first found occurrence.
|
|
92
|
+
- `OBJ.find_all(self, json)`: take a json, return all found occurrence in a list.
|
|
93
|
+
- `OBJ.remove(self, json)`: take a json, remove all found occurrence from it.
|
|
94
|
+
- `OBJ.update_or_create(self, json, value)`: take a json, replace all found occurrence from it, by the value, if doesn't found something, create it.
|
|
95
|
+
- `OBJ.update_or_create_callback(self, json, callback, callback_data)`: take a json, if it doesn't find a parent object, create it, then it calls a callback.
|
|
96
|
+
- `OBJ.callback(self, json, callback, callback_data)`: take a json, call a callback, an all occurrence.
|
|
97
|
+
|
|
98
|
+
`callback` is a function that take 4 arguments: `parent`, `idx`, `cur_value` and `callback_data`
|
|
99
|
+
|
|
100
|
+
Check [`tests`](tests/python/) for more examples
|
|
101
|
+
|
|
102
|
+
### Backends and Direct Usage
|
|
103
|
+
|
|
104
|
+
csonpath is inspired by JSONPath, but is designed to be backend-agnostic: it can work with any C library or environment that manipulates array, object, and scalar types—not just JSON. Out of the box, backends for Python and json-c are provided, but you can create your own backend for other formats such as YAML, or any custom data structure.
|
|
105
|
+
|
|
106
|
+
To use csonpath with a different data type or library, simply define the required macros and types in a header file (similar to `csonpath_json-c.h` or `csonpath_python.c`), then include your backend header before `csonpath.h`. This approach allows you to adapt csonpath for manipulating data in any format that supports array/object semantics, giving you full flexibility beyond just JSON.
|
|
107
|
+
|
|
108
|
+
## Directory Structure
|
|
109
|
+
|
|
110
|
+
- `csonpath.h`, `csonpath_do.h` - Main implementation files
|
|
111
|
+
- `csonpath_json-c.h` - Json-C implementation, use it by including "csonpath_json-c.h" directly in your source
|
|
112
|
+
- `csonpath_python.c` - python implementation, use it like a python lib (so `pip install .`)
|
|
113
|
+
- `tests/` - Contains tests
|
|
114
|
+
- `bench//` - Some benchmarks
|
|
115
|
+
|
|
116
|
+
## 🤝 Contributing
|
|
117
|
+
|
|
118
|
+
We welcome contributions!
|
|
119
|
+
|
|
120
|
+
Please read our [Contributing Guidelines](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) before submitting a pull request.
|
|
121
|
+
|
|
122
|
+
Feel free to open issues or pull requests!
|
|
123
|
+
|
|
124
|
+
## 📜 License
|
|
125
|
+
BSD 3-Clause. See [LICENSE](LICENSE).
|
|
126
|
+
|
csonpath-0.0.1/PKG-INFO
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|