Skip to content

Commit 52980e2

Browse files
Merge pull request #1 from cloudnautique/main
handle json docs containing an object per line
2 parents ad50cc2 + 960ea16 commit 52980e2

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

jq.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function parseArgs() {
77
const argName = val.substring(2);
88
// Check if we are not at the last element and the next element doesn't start with '--'
99
if (index < array.length - 1 && !array[index + 1].startsWith('--')) {
10+
// Directly assign the following value to the argument
1011
args[argName] = array[index + 1];
1112
}
1213
}
@@ -21,7 +22,8 @@ const filter = args.filter || '.';
2122
const jsonPath = args.jsonpath;
2223
const options = {
2324
input: 'file',
24-
output: 'json'
25+
output: 'json',
26+
slurp: args.optionSlurp === 'true'
2527
};
2628

2729
jq.run(filter, jsonPath, options)

tool.gpt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ You are an expert at using the jq cli and know all there is about the functions
88
you will be given a filename that contains JSON data the requester believes answers the ${task}.
99
Do not assume anything about the file structure until the schema has been determined.
1010

11+
When working with files take into account the possibility of null entries.
12+
1113
get the schema of the file from ${filename}.
14+
if the schema was determined with slurp, then consider that in all future queries
1215
plan out the jq queries needed and get the data.
1316
---
1417
name: schema
15-
tools: execute
16-
args: path: path to the json file
18+
tools: execute,sys.stat
19+
args: jsonPath: file and path to execute jq queries against
1720
description: return the schema of the JSON file.
1821

19-
You are given the filepath ${path} to a json file.
22+
You are given the filepath ${jsonPath} to a json file.
23+
24+
As an expert user of jq find out the schema of the file.
25+
If the file is larger then 250kb, use slurp mode first to get the length.
26+
Check the first two objects in slurp mode to ensure the schema is consistent.
2027

21-
As an expert user of jq find out the schema of the file
2228

2329
You can recursively make requests to jq to understand each layer.
2430
if you encounter a list, pick the first one or two items and assume that all items follow the same structure.
@@ -47,13 +53,15 @@ Then return the paths like:
4753
.key2.listOfThings[].thing
4854
...
4955
return the list so it can be determined what to query by other tools
56+
If Slurp mode was used also respond that slurp was true.
5057
---
5158
name: execute
5259
description: execute the jq command line utility to parse data from json files
5360
tools: sys.exec
5461
args: jsonPath: file and path to execute jq queries against
5562
args: filter: the jq filter to pass to the command line
63+
args: optionSlurp: pass false unless you need this, otherwise pass exactly 'true'
5664

5765
#!/bin/bash
5866

59-
node jq.js --jsonpath ${jsonPath} --filter "${filter}"
67+
node jq.js --jsonpath ${jsonPath} --filter "${filter}" --optionSlurp ${optionSlurp}

0 commit comments

Comments
 (0)