0

I'm writing a simple program to read and update data from a JSON file located here: https://api.myjson.com/bins/3ygu6

I already know how to read the file correctly with urllib2.urlopen and json.load, but I have no idea how to update values. Can you please explain me how to do that?

Maybe this could be helpful http://myjson.com/api

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Zero G
  • 117
  • 1
  • 1
  • 10

1 Answers1

0

You could work with parsed JSON as with dictionary, just assign new key or change some value. Also I recommend you to use requests lib, it's more comfortable to use than urllib and json: http://docs.python-requests.org/en/latest/

json_object = requests.get('https://api.myjson.com/bins/3ygu6').json()
json_object['asset5'] = 'ON' 
Eugene Soldatov
  • 9,755
  • 2
  • 35
  • 43
  • Thanks Eugene. I installed requests lib and i ran the code you suggested but this error occours: /usr/local/lib/python2.7/dist-packages/requests-2.8.0-py2.7.egg/requests/packages/urllib3/util/ssl_.py:100: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning – Zero G Oct 13 '15 at 10:53
  • Oh, this is new version of requests. You need also install requests[security] to work with https (pip install requests[security]) or install previous version (pip install requests==2.5.3) - http://stackoverflow.com/questions/29134512/insecureplatformwarning-a-true-sslcontext-object-is-not-available-this-prevent – Eugene Soldatov Oct 13 '15 at 10:55
  • Ok i tried both solutions but they give me the same message : AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name' maybe there's something wrong in my setup? Tell me if you need additional informations. And thanks again. – Zero G Oct 13 '15 at 11:21
  • Seems like you need some additional packages: https://github.com/SiCKRAGETV/sickrage-issues/issues/1566 But it would be simplier for you just use http protocol, i've tried it works fine: http://api.myjson.com/bins/3ygu6 – Eugene Soldatov Oct 13 '15 at 11:27
  • Maybe you put the wrong link at the end of your last comment? Should i try with this solution? http://stackoverflow.com/questions/3290522/urllib2-and-json (i have to study that before i try) – Zero G Oct 13 '15 at 12:39