jsonata-w 1.0.0 → 1.0.1
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.
- package/README.md +9 -5
- package/dist/cli.js +32 -1
- package/package.json +17 -2
package/README.md
CHANGED
|
@@ -40,11 +40,14 @@ jsonata-w transform <file>
|
|
|
40
40
|
The JSONata file MUST start with a configuration comment block:
|
|
41
41
|
|
|
42
42
|
```javascript
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
/**
|
|
44
|
+
* @config {
|
|
45
|
+
* "input": "./path/to/input.json",
|
|
46
|
+
* "output": "./path/to/output.json",
|
|
47
|
+
* "schema": "./optional/schema.json",
|
|
48
|
+
* "examples": "./path/to/example.json"
|
|
49
|
+
* }
|
|
50
|
+
*/
|
|
48
51
|
|
|
49
52
|
(
|
|
50
53
|
/* Your JSONata expression here */
|
|
@@ -55,6 +58,7 @@ The JSONata file MUST start with a configuration comment block:
|
|
|
55
58
|
- `input`: Path to the source JSON file (relative to the .jsonata file).
|
|
56
59
|
- `output`: Path where the transformed JSON will be saved (relative to the .jsonata file).
|
|
57
60
|
- `schema`: (Optional) Path to a JSON schema for validation.
|
|
61
|
+
- `examples`: (Optional) Path to a JSON/YAML file containing the expected output subset for validation.
|
|
58
62
|
|
|
59
63
|
#### Features
|
|
60
64
|
- **Embedded Config**: No need for CLI arguments for input/output.
|
package/dist/cli.js
CHANGED
|
@@ -182,7 +182,38 @@ function pickSubset(data, template) {
|
|
|
182
182
|
const dir = path_1.default.dirname(outputPath);
|
|
183
183
|
if (!fs_1.default.existsSync(dir))
|
|
184
184
|
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
185
|
-
|
|
185
|
+
// Determine output format based on file extension
|
|
186
|
+
const ext = path_1.default.extname(outputPath).toLowerCase();
|
|
187
|
+
let outputContent;
|
|
188
|
+
if (ext === '.yaml' || ext === '.yml') {
|
|
189
|
+
outputContent = js_yaml_1.default.dump(finalResult, { indent: 2, lineWidth: -1 });
|
|
190
|
+
console.log(`Writing YAML output to ${outputPath}...`);
|
|
191
|
+
}
|
|
192
|
+
else if (ext === '.json') {
|
|
193
|
+
outputContent = JSON.stringify(finalResult, null, 2);
|
|
194
|
+
console.log(`Writing JSON output to ${outputPath}...`);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// For other extensions (e.g., .css, .txt, .js), output as string
|
|
198
|
+
// If the result is already a string, use it directly
|
|
199
|
+
// If it's an array of strings, join them
|
|
200
|
+
// Otherwise, convert to string representation
|
|
201
|
+
if (typeof finalResult === 'string') {
|
|
202
|
+
outputContent = finalResult;
|
|
203
|
+
}
|
|
204
|
+
else if (Array.isArray(finalResult) && finalResult.every(item => typeof item === 'string')) {
|
|
205
|
+
outputContent = finalResult.join('');
|
|
206
|
+
}
|
|
207
|
+
else if (typeof finalResult === 'number' || typeof finalResult === 'boolean') {
|
|
208
|
+
outputContent = String(finalResult);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
// For complex objects, still use JSON
|
|
212
|
+
outputContent = JSON.stringify(finalResult, null, 2);
|
|
213
|
+
}
|
|
214
|
+
console.log(`Writing string output to ${outputPath}...`);
|
|
215
|
+
}
|
|
216
|
+
fs_1.default.writeFileSync(outputPath, outputContent);
|
|
186
217
|
console.log(`Transformed ${config.input} -> ${config.output}`);
|
|
187
218
|
}
|
|
188
219
|
catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsonata-w",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Tool to assist AI in transforming JSON files",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -20,6 +20,21 @@
|
|
|
20
20
|
},
|
|
21
21
|
"author": "",
|
|
22
22
|
"license": "ISC",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/pen-drop/jsonata-w.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/pen-drop/jsonata-w/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/pen-drop/jsonata-w#readme",
|
|
31
|
+
"keywords": [
|
|
32
|
+
"jsonata",
|
|
33
|
+
"json",
|
|
34
|
+
"yaml",
|
|
35
|
+
"transform",
|
|
36
|
+
"cli"
|
|
37
|
+
],
|
|
23
38
|
"dependencies": {
|
|
24
39
|
"@types/jsonpath": "^0.2.4",
|
|
25
40
|
"ajv": "^8.17.1",
|
|
@@ -44,4 +59,4 @@
|
|
|
44
59
|
"typescript": "^5.7.2",
|
|
45
60
|
"typescript-eslint": "^8.51.0"
|
|
46
61
|
}
|
|
47
|
-
}
|
|
62
|
+
}
|