Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 524

Converting csv to json with jq

$
0
0

I'm currently practicing converting plain text to csv, and them csv to json. I need to do the conversion only with jq and basic Linux commands.

I didn't have any major problems converting plain text to csv, but further conversion is a bit tricky. Primarily because the first line and the last one are out of standard.

Here is my current csv:

Asserts Samples1;expecting command finishes successfully (bash exe);7ms1;expecting command finishes successfully (loading bin, execute);27ms0;expecting command fails (bash exe, execute);23ms...0;expecting command prints some message (bash exe);12ms0;expecting command prints some message (loading bin, execute);26ms5;2;71.43;136ms

I need to convert this csv to the following format:

{"testName": "Asserts Samples","tests": [   {"name": "expecting command finishes successfully (bash exe)","status": false,"duration": "7ms"   },...   {"name": "expecting command prints some message (loading bin, execute)","status": true,"duration": "26ms"   } ],"summary": {"success": 5,"failed": 2,"rating": 71.43,"duration": "136ms" }}

So far I have figured out:

  • How to add names to values. map({"name": .[1],...
  • How to replace string with boolean. select(.status == "0")).status |= true
  • How to make split with one separator. (split(";")

Long attempts have failed to make a json structure with a corresponding arrays and objects structure.I would be glad for advice or guidance.


Viewing all articles
Browse latest Browse all 524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>