Repair json file without quotes using sed -


how repair json file without quotes using sed or perl or whatever shell script tool? add double quotes (e.g. "glossary"). below sample json. lot!

{     glossary: {         title: "example glossary",             glossdiv: {                 title: "s",                 glosslist: {                     glossentry: {                         id: "sgml",                         sortas: "sgml",                         glossterm: "standard generalized markup language",                         acronym: "sgml",                         abbrev: "iso 8879:1986",                         glossdef: {                             para: "a meta-markup language, used create markup languages such docbook.",                             glossseealso: ["gml", "xml"]                         },                     glosssee: "markup"                 }             }         }     } } 

this quick , dirty one-liner works example. json format must "pretty-printed" same input example. attribute names should follow pattern: [a-za-z_]+

sed -r 's/(\s*)([a-za-z_]+)/\1"\2"/' file 

it outputs:

{     "glossary": {         "title": "example glossary",             "glossdiv": {                 "title": "s",                 "glosslist": {                     "glossentry": {                         "id": "sgml",                         "sortas": "sgml",                         "glossterm": "standard generalized markup language",                         "acronym": "sgml",                         "abbrev": "iso 8879:1986",                         "glossdef": {                             "para": "a meta-markup language, used create markup languages such docbook.",                             "glossseealso": ["gml", "xml"]                         },                     "glosssee": "markup"                 }             }         }     } } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -