How to add in double quotation first word of each line via sed?

Issue

I have files with similar content but I want to make it a valid JSON I need to add every word of a line in a double quotation mark.
I tried existing answers on StackOverflow but none of them works properly.

{container:"proxy",
 endpoint:"proxy",
 exception:"ApiException"}

transfer to the following format:

  {"container":"proxy",
     "endpoint":"proxy",
     "exception":"ApiException"}

Solution

You may be able to treat each file as a jq filter that generates an object. For example,

$ cat tmp.jq
{container:"proxy",
 endpoint:"proxy",
 exception:"ApiException",
 instance:"133.3.12.250:9030"}
$ jq -nf tmp.jq
{
  "container": "proxy",
  "endpoint": "proxy",
  "exception": "ApiException",
  "instance": "133.3.12.250:9030"
}

Answered By – chepner

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published