In [8]:
import re
import json

In [2]:
txt="""<row Id="6" PostTypeId="1" AcceptedAnswerId="31" CreationDate="2008-07-31T22:08:08.620" Score="256" ViewCount="16306" Body="&lt;p&gt;I have an absolutely positioned &lt;code&gt;div&lt;/code&gt; containing several children, one of which is a relatively positioned &lt;code&gt;div&lt;/code&gt;. When I use a &lt;strong&gt;percentage-based width&lt;/strong&gt; on the child &lt;code&gt;div&lt;/code&gt;, it collapses to '0' width on &lt;a href=&quot;http://en.wikipedia.org/wiki/Internet_Explorer_7&quot; rel=&quot;noreferrer&quot;&gt;Internet&amp;nbsp;Explorer&amp;nbsp;7&lt;/a&gt;, but not on Firefox or Safari.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I use &lt;strong&gt;pixel width&lt;/strong&gt;, it works. If the parent is relatively positioned, the percentage width on the child works.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Is there something I'm missing here?&lt;/li&gt;&#xA;&lt;li&gt;Is there an easy fix for this besides the &lt;em&gt;pixel-based width&lt;/em&gt; on the&#xA;child?&lt;/li&gt;&#xA;&lt;li&gt;Is there an area of the CSS specification that covers this?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="9" LastEditorUserId="63550" LastEditorDisplayName="Rich B" LastEditDate="2016-03-19T06:05:48.487" LastActivityDate="2016-03-19T06:10:52.170" Title="Percentage width child element in absolutely positioned parent on Internet Explorer 7" Tags="&lt;html&gt;&lt;css&gt;&lt;css3&gt;&lt;internet-explorer-7&gt;" AnswerCount="5" CommentCount="0" FavoriteCount="10" />"""

In [34]:
out = txt.strip()
out = out.replace('<row','{')
out = out.replace(' />','}')

out = re.sub(r' ([^=]+)="([^"]+)"',r'"\1":"\2",',out)

out = re.sub(r':"(\d+)"',r':\1',out)

out


Out[34]:
'{"Id":6,"PostTypeId":1,"AcceptedAnswerId":31,"CreationDate":"2008-07-31T22:08:08.620","Score":256,"ViewCount":16306,"Body":"&lt;p&gt;I have an absolutely positioned &lt;code&gt;div&lt;/code&gt; containing several children, one of which is a relatively positioned &lt;code&gt;div&lt;/code&gt;. When I use a &lt;strong&gt;percentage-based width&lt;/strong&gt; on the child &lt;code&gt;div&lt;/code&gt;, it collapses to \'0\' width on &lt;a href=&quot;http://en.wikipedia.org/wiki/Internet_Explorer_7&quot; rel=&quot;noreferrer&quot;&gt;Internet&amp;nbsp;Explorer&amp;nbsp;7&lt;/a&gt;, but not on Firefox or Safari.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I use &lt;strong&gt;pixel width&lt;/strong&gt;, it works. If the parent is relatively positioned, the percentage width on the child works.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Is there something I\'m missing here?&lt;/li&gt;&#xA;&lt;li&gt;Is there an easy fix for this besides the &lt;em&gt;pixel-based width&lt;/em&gt; on the&#xA;child?&lt;/li&gt;&#xA;&lt;li&gt;Is there an area of the CSS specification that covers this?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;","OwnerUserId":9,"LastEditorUserId":63550,"LastEditorDisplayName":"Rich B","LastEditDate":"2016-03-19T06:05:48.487","LastActivityDate":"2016-03-19T06:10:52.170","Title":"Percentage width child element in absolutely positioned parent on Internet Explorer 7","Tags":"&lt;html&gt;&lt;css&gt;&lt;css3&gt;&lt;internet-explorer-7&gt;","AnswerCount":5,"CommentCount":0,"FavoriteCount":10,}'

In [29]:
out


Out[29]:
'{"Id":"6","PostTypeId":"1","AcceptedAnswerId":"31","CreationDate":"2008-07-31T22:08:08.620","Score":"256","ViewCount":"16306","Body":"&lt;p&gt;I have an absolutely positioned &lt;code&gt;div&lt;/code&gt; containing several children, one of which is a relatively positioned &lt;code&gt;div&lt;/code&gt;. When I use a &lt;strong&gt;percentage-based width&lt;/strong&gt; on the child &lt;code&gt;div&lt;/code&gt;, it collapses to \'0\' width on &lt;a href=&quot;http://en.wikipedia.org/wiki/Internet_Explorer_7&quot; rel=&quot;noreferrer&quot;&gt;Internet&amp;nbsp;Explorer&amp;nbsp;7&lt;/a&gt;, but not on Firefox or Safari.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I use &lt;strong&gt;pixel width&lt;/strong&gt;, it works. If the parent is relatively positioned, the percentage width on the child works.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Is there something I\'m missing here?&lt;/li&gt;&#xA;&lt;li&gt;Is there an easy fix for this besides the &lt;em&gt;pixel-based width&lt;/em&gt; on the&#xA;child?&lt;/li&gt;&#xA;&lt;li&gt;Is there an area of the CSS specification that covers this?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;","OwnerUserId":"9","LastEditorUserId":"63550","LastEditorDisplayName":"Rich B","LastEditDate":"2016-03-19T06:05:48.487","LastActivityDate":"2016-03-19T06:10:52.170","Title":"Percentage width child element in absolutely positioned parent on Internet Explorer 7","Tags":"&lt;html&gt;&lt;css&gt;&lt;css3&gt;&lt;internet-explorer-7&gt;","AnswerCount":"5","CommentCount":"0","FavoriteCount":"10",}'

In [17]:
json.loads(out)


---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-17-8df2e2b44012> in <module>()
----> 1 json.loads(out)

/usr/lib/python3.5/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    317             parse_int is None and parse_float is None and
    318             parse_constant is None and object_pairs_hook is None and not kw):
--> 319         return _default_decoder.decode(s)
    320     if cls is None:
    321         cls = JSONDecoder

/usr/lib/python3.5/json/decoder.py in decode(self, s, _w)
    337 
    338         """
--> 339         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    340         end = _w(s, end).end()
    341         if end != len(s):

/usr/lib/python3.5/json/decoder.py in raw_decode(self, s, idx)
    353         """
    354         try:
--> 355             obj, end = self.scan_once(s, idx)
    356         except StopIteration as err:
    357             raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 583 (char 582)

In [4]:
json


Out[4]:
'<row"Id":"6","PostTypeId":"1","AcceptedAnswerId":"31","CreationDate":"2008-07-31T22:08:08.620","Score":"256","ViewCount":"16306","Body":"&lt;p&gt;I have an absolutely positioned &lt;code&gt;div&lt;/code&gt; containing several children, one of which is a relatively positioned &lt;code&gt;div&lt;/code&gt;. When I use a &lt;strong&gt;percentage-based width&lt;/strong&gt; on the child &lt;code&gt;div&lt;/code&gt;, it collapses to \'0\' width on &lt;a href=&quot;http://en.wikipedia.org/wiki/Internet_Explorer_7&quot; rel=&quot;noreferrer&quot;&gt;Internet&amp;nbsp;Explorer&amp;nbsp;7&lt;/a&gt;, but not on Firefox or Safari.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I use &lt;strong&gt;pixel width&lt;/strong&gt;, it works. If the parent is relatively positioned, the percentage width on the child works.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Is there something I\'m missing here?&lt;/li&gt;&#xA;&lt;li&gt;Is there an easy fix for this besides the &lt;em&gt;pixel-based width&lt;/em&gt; on the&#xA;child?&lt;/li&gt;&#xA;&lt;li&gt;Is there an area of the CSS specification that covers this?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;","OwnerUserId":"9","LastEditorUserId":"63550","LastEditorDisplayName":"Rich B","LastEditDate":"2016-03-19T06:05:48.487","LastActivityDate":"2016-03-19T06:10:52.170","Title":"Percentage width child element in absolutely positioned parent on Internet Explorer 7","Tags":"&lt;html&gt;&lt;css&gt;&lt;css3&gt;&lt;internet-explorer-7&gt;","AnswerCount":"5","CommentCount":"0","FavoriteCount":"10", />'

In [ ]: