This is a command line tool based on graalson-trax, a Java based JSON transformer that uses Javascript templates to create JSON output.
https://github.com/warrenc5/graalson-trax
JsonT templateFile [inputJson|-] [outputFile|-] [charset|UTF-8]
- templateFile a javascript location - resourcePath passed to Source constructor
- inputJson a resourcePath or a filePath or - to indicate STDIN (default)
- outputFile a filePath or - to indicate STDOUT (default)
- charset defaults to UTF-& for input and output.
example:
java -classpath src/test/resources:
find target -name \*.jar | tr -t '\n' ':'JsonT template.js src/test/resources/ALL_FINES.json all_fines_nsw.json UTF-8 cat src/test/resources/ALL_FINES.json | java -classpath src/test/resources:find target -name \*.jar | tr -t '\n' ':'JsonT template.js > all_fines_nsw.json
const hits = _.hits.hits
const l = hits.length
function expand(o) {
return {t:o.offence}
}
$ = {
results: hits.map(h=> [
"'" + (h.fields === undefined ? "<none>": h.fields.Description[0]) + "'",
h._source.Points,
h._source.Fine,
h._source.type,
"'"+h._source.Section+"'",
].join(',')).sort()
}
-rw-rw-r-- 1 wozza wozza 71977 Dec 3 08:44 all_fines_nsw.csv
{
results: [
'AFM hours - critical',4,$20,590,DRIVER FATIGUE,'Sec 258 (1)',
'AFM hours - severe',3,$13,730,DRIVER FATIGUE,'Sec 258 (1)',
'Approach children�s crossing too quickly to stop safely (school zone)',4,$704,PEDESTRIAN CROSSINGS,'Rule 80 (1)',
'Approach children�s crossing too quickly to stop safely',3,$562,PEDESTRIAN CROSSINGS,'Rule 80 (1)',
Library is uses Graalson & Graalson-Trax
https://www.github.com/warrenc5/graalson-trax
<dependency>
<groupId>mobi.mofokom</groupId>
<artifactId>graalson-trax</artifactId>
<version>1.0.3</version>
</dependency>
And
https://www.github.com/warrenc5/graalson
<dependency>
<groupId>mobi.mofokom</groupId>
<artifactId>graalson</artifactId>
<version>1.0.5</version>
</dependency>