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

Convert json to Markdown Table in bash

$
0
0

I am trying to convert the below json to a markdown table(GitHub docs(.md file)), however not able to do so.

{"service_1":"abc-endpoint.vpce.amazonaws.com","service_2":"def-endpoint.vpce.amazonaws.com","service_3":"xyz-endpoint.vpce.amazonaws.com"}

Command I tried:

cat json_file | jq -r '{"NAME": "ENDPOINT_ID"} + . | to_entries[] | "\(.key)\t\(.value)"'

Output I am getting:

 NAME         ENDPOINT-IDservice_1    abc-endpoint.vpce.amazonaws.comservice_2    def-endpoint.vpce.amazonaws.comservice_3    xyz-endpoint.vpce.amazonaws.com

The above output when committed to README.md github file losses its indentation(spaces) and is not properly divided into rows and columns, leading to bad visualization.

Link that I went through:

https://www.markdownguide.org/extended-syntax/#tables

Expected output:

|    NAME    | ENDPOINT_ID || --------   | -------- || service_1  | abc-endpoint.vpce.amazonaws.com   || service_2  | def-endpoint.vpce.amazonaws.com   || service_3  | xyz-endpoint.vpce.amazonaws.com   |

Viewing all articles
Browse latest Browse all 522

Trending Articles



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