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
Post a Comment