What is the best way to quote unquoted strings while leaving already quoted strings alone?
<p>I have a large block of text that is almost JSON, but is not quite. I need to make it JSON so that I can process it. Specifically, it is the "marks" object in the code at the following page: <a href="https://en.wikipedia.org/wiki/Module:Syrian_Civil_War_detailed_map" rel="nofollow">https://en.wikipedia.org/wiki/Module:Syrian_Civil_War_detailed_map</a></p>

<p>Some of the strings there are already quoted. Some of them are not. I need to quote all the strings and leave the already-quoted ones alone. For example, with the following almost-JSON-object:</p>

<pre><code>marks = {
    lat = 36.103,
    long = 37.308,
    mark = m.gov_hill,
    marksize = 184,
    label = "[[Battle of Aleppo (2012âpresent)|Aleppo]]",
    link = "Battle of Aleppo (2012âpresent)",
    label_size = 0,
    position = "left"
}
</code></pre>

<p>I need it to become this:</p>

<pre><code>"marks" = {
    "lat" = 36.103,
    "long" = 37.308,
    "mark" = "m.gov_hill",
    "marksize" = 184,
    "label" = "[[Battle of Aleppo (2012âpresent)|Aleppo]]",
    "link" = "Battle of Aleppo (2012âpresent)",
    "label_size" = 0,
    "position" = "left"
}
</code></pre>

<p>Essentially, anything that can become a string and is not already a string should be turned into a string. Also, I already have a sed command for turning the equals signs into colons as one of the steps to turning it into valid JSON, so no need to comment on that part of the process.</p>

<p>Thanks in advance!</p>

<pre><code>$ cat tst.awk
/=/ {
    lhs = rhs = $0
    sub(/[[:space:]]*=.*/,"",lhs)
    sub(/^[^=]+=[[:space:]]*/,"",rhs)

    sub(/[^[:space:]]+/,"\"&amp;\"",lhs)

    if ( rhs !~ /^([0-9]+\.?[0-9]*|".*"),?$/ ) {
        sub(/,?$/,"\"&amp;",rhs)
        rhs = "\"" rhs
    }

    $0 = lhs " = " rhs
}
{ print }

$ awk -f tst.awk file
"marks" = "{"
    "lat" = 36.103,
    "long" = 37.308,
    "mark" = "m.gov_hill",
    "marksize" = 184,
    "label" = "[[Battle of Aleppo (2012âpresent)|Aleppo]]",
    "link" = "Battle of Aleppo (2012âpresent)",
    "label_size" = 0,
    "position" = "left"
}
</code></pre>

<p>The above should work even for the non-trivial  cases I mentioned in my comment under your question.</p>

python json regex string sed