Jq stuff: Difference between revisions

From SoftwareGuy
Jump to navigation Jump to search
Mark (talk | contribs)
No edit summary
Mark (talk | contribs)
No edit summary
Line 13: Line 13:
<pre>
<pre>
"0_0_0","681.0"
"0_0_0","681.0"
"1_0_1","684.0"
"1_0_1","684.0"
"2_0_2","684.0"
"2_0_2","684.0"
"3_0_3","699.0"
"3_0_3","699.0"
"4_0_4","693.0"
"4_0_4","693.0"
"5_0_5",
"5_0_5",
"6_0_6",
"6_0_6",
"7_0_7",
"7_0_7",
"8_0_8",
"8_0_8",
"9_0_9",
"9_0_9",
"10_0_10",
"10_0_10",
"11_0_11",
"11_0_11",
"12_1_0","708.0"
"12_1_0","708.0"
"13_1_1","726.0"
"13_1_1","726.0"
"14_1_2","738.0"
"14_1_2","738.0"
"15_1_3","750.0"
"15_1_3","750.0"
"16_1_4","765.0"
"16_1_4","765.0"
"17_1_5",
"17_1_5",
"18_1_6",
"18_1_6",
"19_1_7",
"19_1_7",
"20_1_8",
"20_1_8",
"21_1_9",
"21_1_9",
"22_1_10",
"22_1_10",
"23_1_11",
"23_1_11",
"24_2_0","775.0"
"24_2_0","775.0"
"25_2_1","830.0"
"25_2_1","830.0"
"26_2_2","830.0"
"26_2_2","830.0"
"27_2_3","802.0"
"27_2_3","802.0"
"28_2_4","767.0"
"28_2_4","767.0"
"29_2_5","767.0"
"29_2_5","767.0"
"30_2_6",
"30_2_6",
"31_2_7",
"31_2_7",
"32_2_8",
"32_2_8",
"33_2_9",
"33_2_9",
"34_2_10",
"34_2_10",
"35_2_11",
"35_2_11",
"36_3_0","855.0"
"36_3_0","855.0"
"37_3_1","910.0"
"37_3_1","910.0"
"38_3_2","885.0"
"38_3_2","885.0"
"39_3_3","860.0"
"39_3_3","860.0"
"40_3_4","849.0"
"40_3_4","849.0"
"41_3_5","860.0"
"41_3_5","860.0"
"42_3_6",
"42_3_6",
"43_3_7",
"43_3_7",
"44_3_8",
"44_3_8",
"45_3_9",
"45_3_9",
"46_3_10",
"46_3_10",
"47_3_11",
"47_3_11",
</pre>
</pre>

Revision as of 13:12, 20 March 2023

Making csv output from a json input, example.

Staring with the follow sample json:

{"avg":16383,"detectorStatus":[{"sumBPort":"0","isAvailable":"true","temp":"33.0","isHvAdequate":"true","hvSetPoint":"681.0","threshold":"-22000","id":"0_0_0","hvEnabled":"true","iobPort":"0","hv":"656.0"},{"sumBPort":"1","isAvailable":"true","temp":"33.75","isHvAdequate":"true","hvSetPoint":"684.0","threshold":"-22000","id":"1_0_1","hvEnabled":"true","iobPort":"0","hv":"660.0"},{"sumBPort":"2","isAvailable":"true","temp":"33.875","isHvAdequate":"true","hvSetPoint":"684.0","threshold":"-22000","id":"2_0_2","hvEnabled":"true","iobPort":"0","hv":"660.0"},{"sumBPort":"3","isAvailable":"true","temp":"34.25","isHvAdequate":"true","hvSetPoint":"699.0","threshold":"-22000","id":"3_0_3","hvEnabled":"true","iobPort":"0","hv":"676.0"},{"sumBPort":"4","isAvailable":"true","temp":"35.0","isHvAdequate":"true","hvSetPoint":"693.0","threshold":"-22000","id":"4_0_4","hvEnabled":"true","iobPort":"0","hv":"668.0"},{"sumBPort":"5","isAvailable":"false","id":"5_0_5","iobPort":"0"},{"sumBPort":"6","isAvailable":"false","id":"6_0_6","iobPort":"0"},{"sumBPort":"7","isAvailable":"false","id":"7_0_7","iobPort":"0"},{"sumBPort":"8","isAvailable":"false","id":"8_0_8","iobPort":"0"},{"sumBPort":"9","isAvailable":"false","id":"9_0_9","iobPort":"0"},{"sumBPort":"10","isAvailable":"false","id":"10_0_10","iobPort":"0"},{"sumBPort":"11","isAvailable":"false","id":"11_0_11","iobPort":"0"},{"sumBPort":"0","isAvailable":"true","temp":"34.0","isHvAdequate":"true","hvSetPoint":"708.0","threshold":"-22000","id":"12_1_0","hvEnabled":"true","iobPort":"1","hv":"684.0"},{"sumBPort":"1","isAvailable":"true","temp":"34.0","isHvAdequate":"true","hvSetPoint":"726.0","threshold":"-22000","id":"13_1_1","hvEnabled":"true","iobPort":"1","hv":"699.0"},{"sumBPort":"2","isAvailable":"true","temp":"34.5","isHvAdequate":"true","hvSetPoint":"738.0","threshold":"-22000","id":"14_1_2","hvEnabled":"true","iobPort":"1","hv":"715.0"},{"sumBPort":"3","isAvailable":"true","temp":"35.375","isHvAdequate":"true","hvSetPoint":"750.0","threshold":"-22000","id":"15_1_3","hvEnabled":"true","iobPort":"1","hv":"730.0"},{"sumBPort":"4","isAvailable":"true","temp":"36.0","isHvAdequate":"true","hvSetPoint":"765.0","threshold":"-22000","id":"16_1_4","hvEnabled":"true","iobPort":"1","hv":"742.0"},{"sumBPort":"5","isAvailable":"false","id":"17_1_5","iobPort":"1"},{"sumBPort":"6","isAvailable":"false","id":"18_1_6","iobPort":"1"},{"sumBPort":"7","isAvailable":"false","id":"19_1_7","iobPort":"1"},{"sumBPort":"8","isAvailable":"false","id":"20_1_8","iobPort":"1"},{"sumBPort":"9","isAvailable":"false","id":"21_1_9","iobPort":"1"},{"sumBPort":"10","isAvailable":"false","id":"22_1_10","iobPort":"1"},{"sumBPort":"11","isAvailable":"false","id":"23_1_11","iobPort":"1"},{"sumBPort":"0","isAvailable":"true","temp":"30.875","isHvAdequate":"true","hvSetPoint":"775.0","threshold":"-1","id":"24_2_0","hvEnabled":"true","iobPort":"2","hv":"699.0"},{"sumBPort":"1","isAvailable":"true","temp":"27.875","isHvAdequate":"true","hvSetPoint":"830.0","threshold":"-1","id":"25_2_1","hvEnabled":"true","iobPort":"2","hv":"758.0"},{"sumBPort":"2","isAvailable":"true","temp":"26.875","isHvAdequate":"true","hvSetPoint":"830.0","threshold":"-22000","id":"26_2_2","hvEnabled":"true","iobPort":"2","hv":"754.0"},{"sumBPort":"3","isAvailable":"true","temp":"26.875","isHvAdequate":"true","hvSetPoint":"802.0","threshold":"-1","id":"27_2_3","hvEnabled":"true","iobPort":"2","hv":"777.0"},{"sumBPort":"4","isAvailable":"true","temp":"25.875","isHvAdequate":"true","hvSetPoint":"767.0","threshold":"-1","id":"28_2_4","hvEnabled":"true","iobPort":"2","hv":"734.0"},{"sumBPort":"5","isAvailable":"true","temp":"27.875","isHvAdequate":"true","hvSetPoint":"767.0","threshold":"-1","id":"29_2_5","hvEnabled":"true","iobPort":"2","hv":"691.0"},{"sumBPort":"6","isAvailable":"false","id":"30_2_6","iobPort":"2"},{"sumBPort":"7","isAvailable":"false","id":"31_2_7","iobPort":"2"},{"sumBPort":"8","isAvailable":"false","id":"32_2_8","iobPort":"2"},{"sumBPort":"9","isAvailable":"false","id":"33_2_9","iobPort":"2"},{"sumBPort":"10","isAvailable":"false","id":"34_2_10","iobPort":"2"},{"sumBPort":"11","isAvailable":"false","id":"35_2_11","iobPort":"2"},{"sumBPort":"0","isAvailable":"true","temp":"30.875","isHvAdequate":"true","hvSetPoint":"855.0","threshold":"-1","id":"36_3_0","hvEnabled":"true","iobPort":"3","hv":"793.0"},{"sumBPort":"1","isAvailable":"true","temp":"26.875","isHvAdequate":"true","hvSetPoint":"910.0","threshold":"-5000","id":"37_3_1","hvEnabled":"true","iobPort":"3","hv":"855.0"},{"sumBPort":"2","isAvailable":"true","temp":"26.875","isHvAdequate":"true","hvSetPoint":"885.0","threshold":"-22000","id":"38_3_2","hvEnabled":"true","iobPort":"3","hv":"855.0"},{"sumBPort":"3","isAvailable":"true","temp":"24.875","isHvAdequate":"true","hvSetPoint":"860.0","threshold":"-1","id":"39_3_3","hvEnabled":"true","iobPort":"3","hv":"828.0"},{"sumBPort":"4","isAvailable":"true","temp":"24.875","isHvAdequate":"true","hvSetPoint":"849.0","threshold":"-1","id":"40_3_4","hvEnabled":"true","iobPort":"3","hv":"781.0"},{"sumBPort":"5","isAvailable":"true","temp":"27.875","isHvAdequate":"true","hvSetPoint":"860.0","threshold":"-1","id":"41_3_5","hvEnabled":"true","iobPort":"3","hv":"797.0"},{"sumBPort":"6","isAvailable":"false","id":"42_3_6","iobPort":"3"},{"sumBPort":"7","isAvailable":"false","id":"43_3_7","iobPort":"3"},{"sumBPort":"8","isAvailable":"false","id":"44_3_8","iobPort":"3"},{"sumBPort":"9","isAvailable":"false","id":"45_3_9","iobPort":"3"},{"sumBPort":"10","isAvailable":"false","id":"46_3_10","iobPort":"3"},{"sumBPort":"11","isAvailable":"false","id":"47_3_11","iobPort":"3"}],"determinationMade":false,"duration":22.461,"highSpeedViolation":false,"isSuspicious":false,"lowSpeedViolation":false,"max":-32768,"min":65535,"mph":1.8530931,"pb":0,"pixelsPerRaster":1000,"rastersPerImage":0,"renderData":{"claheCellHeightDiv":75,"claheCellWidthDiv":72,"claheClipLimit":1.2,"claheOn":true,"colorMap":0,"editVersion":0,"gaussianHeight":5,"gaussianWidth":5,"histoHigh":255,"histoLow":0,"impulseRemovalOn":false,"mConfig":{"claheCellHeightDiv":75,"claheCellWidthDiv":72,"claheClipLimit":1.2,"claheOn":true,"colorMap":0,"gaussianHeight":5,"gaussianWidth":5,"histoHigh":255,"histoLow":0,"impulseRemovalOn":false,"sharpenValue":0.5,"uniformSampleOn":false},"pixelCount":0,"scaleFactor":2.4707909,"sharpenValue":0.5,"type":"uvx","uniformSampleOn":false},"scanId":"26","systemSerialNumber":"fa4c5a84-3ab8-403d-a1b9-18a2351bcdfa","timestamp":"Thu Mar 16 21:05:37 GMT+00:00 2023","version":1.2}

Using the following command will generate the desired csv output:

jq -r '.detectorStatus[] | [.id, .hvSetPoint] | @csv' 26.json > 26.csv

Resulting in the following data:

"0_0_0","681.0"
"1_0_1","684.0"
"2_0_2","684.0"
"3_0_3","699.0"
"4_0_4","693.0"
"5_0_5",
"6_0_6",
"7_0_7",
"8_0_8",
"9_0_9",
"10_0_10",
"11_0_11",
"12_1_0","708.0"
"13_1_1","726.0"
"14_1_2","738.0"
"15_1_3","750.0"
"16_1_4","765.0"
"17_1_5",
"18_1_6",
"19_1_7",
"20_1_8",
"21_1_9",
"22_1_10",
"23_1_11",
"24_2_0","775.0"
"25_2_1","830.0"
"26_2_2","830.0"
"27_2_3","802.0"
"28_2_4","767.0"
"29_2_5","767.0"
"30_2_6",
"31_2_7",
"32_2_8",
"33_2_9",
"34_2_10",
"35_2_11",
"36_3_0","855.0"
"37_3_1","910.0"
"38_3_2","885.0"
"39_3_3","860.0"
"40_3_4","849.0"
"41_3_5","860.0"
"42_3_6",
"43_3_7",
"44_3_8",
"45_3_9",
"46_3_10",
"47_3_11",