Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two problems here. First:</p> <pre><code>string = file("prCounties.txt","r").read().decode('utf-8') </code></pre> <p>Why are you decoding it? JSON explicitly takes UTF-8 strings. That's part of the definition of JSON. The fact that <code>simplejson</code> can handle Unicode strings makes it a little easier to use, but it effectively handles them by encoding them back to UTF-8, so… why not just leave it that way in the first place?</p> <p>More importantly, where did your data come from? If <code>prCounties.txt</code> has that <code>u"Añasco"</code> in it, it's not JSON. You can't encode something to one standard and decode to a completely different standard just because they look similar.</p> <p>If, for example, you did <code>open('prCounties.txt', 'w').write(repr(my_dict))</code>, you have to read it back with a Python <code>repr</code> parser (possibly <code>ast.literal_eval</code>, or maybe you have to write something yourself).</p> <p>Or, alternatively, if you want to parse the data as JSON, write it as JSON in the first place.</p> <hr> <p>According to your comment, the data was read from <a href="https://raw.github.com/johan/world.geo.json/master/countries/USA/PR" rel="nofollow">https://raw.github.com/johan/world.geo.json/master/countries/USA/PR</a>/Añasco.geo.json</p> <p>The raw contents of that URL are:</p> <pre><code>{"type":"FeatureCollection","properties":{"kind":"state","state":"PR"},"features":[ {"type":"Feature","properties":{"kind":"county","name":"Añasco","state":"PR"},"geometry":{"type":"MultiPolygon","coordinates":[[[[-67.1220,18.3239],[-67.0508,18.3075],[-67.0398,18.2910],[-67.0837,18.2527],[-67.1220,18.2417],[-67.1603,18.2746],[-67.1877,18.2691],[-67.2261,18.2965],[-67.1822,18.3129],[-67.1275,18.3184]]]]}} ]} </code></pre> <p>You'll notice that there is no <code>"name": u"Añasco"</code> (or <code>"name": u"A\xf1asco"</code>, or anything similar) there. You can read this just by calling <code>read</code>—no need to decode it from UTF-8 or anything—and just pass it to <code>simplejson.loads</code> and it works just fine:</p> <pre><code>$ curl -O https://raw.github.com/johan/world.geo.json/master/countries/USA/PR/Añasco.geo.json $ cp Añasco.geo.json prCounties.txt $ python &gt;&gt;&gt; import simplejson &gt;&gt;&gt; string = file("prCounties.txt","r").read() &gt;&gt;&gt; d = simplejson.loads(string) &gt;&gt;&gt; print d {u'type': u'FeatureCollection', u'properties': {u'kind': u'state', u'state': u'PR'}, u'features': [{u'geometry': {u'type': u'MultiPolygon', u'coordinates': [[[[-67.122, 18.3239], [-67.0508, 18.3075], [-67.0398, 18.291], [-67.0837, 18.2527], [-67.122, 18.2417], [-67.1603, 18.2746], [-67.1877, 18.2691], [-67.2261, 18.2965], [-67.1822, 18.3129], [-67.1275, 18.3184]]]]}, u'type': u'Feature', u'properties': {u'kind': u'county', u'name': u'A\xf1asco', u'state': u'PR'}}]} </code></pre> <p>See, no errors at all.</p> <p>Somewhere, you've done something to this data to turn it into something else which is not JSON. My guess is that, on top of doing a bunch of unnecessary extra <code>decode</code> and <code>encode</code> calls, you've also done a <code>simplejson.loads</code>, then tried to re-<code>simplejson.loads</code> the <code>repr</code> of the <code>dict</code> you got back. Or maybe you've JSON-encoded a <code>dict</code> full of already-encoded JSON strings. Whatever you've done, that code, not the code you're showing us, is where the error is.</p> <p>And the easiest fix is probably to generate <code>prCounties.txt</code> properly in the first place. It's just 70-odd downloads of a few lines apiece, and it should take maybe 2 lines of bash or 4 lines of Python to do it…</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload