python program to read a specific field in json file outpouting errosHow do I copy a file in Python?Why can't Python parse this JSON data?If Python is interpreted, what are .pyc files?How to read a file line-by-line into a list?Find all files in a directory with extension .txt in PythonHow do you append to a file in Python?How to read a text file into a string variable and strip newlines?Why is reading lines from stdin much slower in C++ than Python?How do I write JSON data to a file?How to prettyprint a JSON file?

Was it ever illegal to name a pig "Napoleon" in France?

Is there a formal/better word than "skyrocket" for the given context?

Why does Trump want a citizenship question on the census?

Perl regex matching apostrophe fails

Can a landlord force all residents to use the landlord's in-house debit card accounts?

When do flights get cancelled due to fog?

How does one acquire an undead eyeball encased in a gem?

How should I ask for a "pint" in countries that use metric?

Intern not wearing safety equipment; how could I have handled this differently?

How to use Adostop Eco stop bath?

What factors could lead to bishops establishing monastic armies?

Who goes first? Person disembarking bus or the bicycle?

What was the profession 芸者 (female entertainer) called in Russia?

Publishing papers seem natural to many, while I find it really hard to think novel stuff to pursue till publication. How to cope up with this?

Write a function

How can I know how much authority/decision making power etc I have as an employee?

How do I separate enchants from items?

What was the significance of Spider-Man: Far From Home being an MCU Phase 3 film instead of a Phase 4 film?

stuck in/at beta

Category-theoretic treatment of diffs, patches and merging?

Is it ok for parents to kiss and romance with each other while their 2- to 8-year-old child watches?

What was the nature of the known bugs in the Space Shuttle software?

Blocks from @ jafe

Can the word "desk" be used as a verb?



python program to read a specific field in json file outpouting erros


How do I copy a file in Python?Why can't Python parse this JSON data?If Python is interpreted, what are .pyc files?How to read a file line-by-line into a list?Find all files in a directory with extension .txt in PythonHow do you append to a file in Python?How to read a text file into a string variable and strip newlines?Why is reading lines from stdin much slower in C++ than Python?How do I write JSON data to a file?How to prettyprint a JSON file?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















so i have the following code



import json

with open("output.json") as f:
data = json.loads(f.read())
print(data[0]['url'])


the thing is i get the following errors when i try to give it a file to process



Traceback (most recent call last):
File "C:/Users/pedre/PycharmProjects/app_pdi/app_pdi.py", line 6, in <module>
data = json.loads(f.read())
File "C:UserspedreAppDataLocalProgramsPythonPython37-32libjson__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:UserspedreAppDataLocalProgramsPythonPython37-32libjsondecoder.py", line 340, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 408)


i am using PyCharm to write my code, can some one help me ? i am quite new to Python so please be nice xD



EDIT1:



my JSON file has the following structure:



"urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8"
"urlkey": "pt,gov,70ja)/robots.txt", "timestamp": "20190221024013", "url": "http://70ja.gov.pt/robots.txt", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/robotstxt/CC-MAIN-20190221010932-20190221032932-00489.warc.gz", "mime-detected": "text/plain", "offset": "23166", "digest": "5S2OB6LK7EHO74WNBNVLNE6ZBB5VRYTI", "status": "200", "length": "818", "mime": "text/plain"
"urlkey": "pt,gov,academiaportuguesadahistoria)/", "timestamp": "20190218105706", "url": "https://academiaportuguesadahistoria.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247484928.52/warc/CC-MAIN-20190218094308-20190218120308-00509.warc.gz", "mime-detected": "text/html", "offset": "498335094", "digest": "EQOJY7DY2YL752S6QCRXLGNDTELPYLD3", "languages": "por", "status": "200", "length": "10240", "mime": "text/html", "charset": "UTF-8"









share|improve this question






























    1















    so i have the following code



    import json

    with open("output.json") as f:
    data = json.loads(f.read())
    print(data[0]['url'])


    the thing is i get the following errors when i try to give it a file to process



    Traceback (most recent call last):
    File "C:/Users/pedre/PycharmProjects/app_pdi/app_pdi.py", line 6, in <module>
    data = json.loads(f.read())
    File "C:UserspedreAppDataLocalProgramsPythonPython37-32libjson__init__.py", line 348, in loads
    return _default_decoder.decode(s)
    File "C:UserspedreAppDataLocalProgramsPythonPython37-32libjsondecoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
    json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 408)


    i am using PyCharm to write my code, can some one help me ? i am quite new to Python so please be nice xD



    EDIT1:



    my JSON file has the following structure:



    "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8"
    "urlkey": "pt,gov,70ja)/robots.txt", "timestamp": "20190221024013", "url": "http://70ja.gov.pt/robots.txt", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/robotstxt/CC-MAIN-20190221010932-20190221032932-00489.warc.gz", "mime-detected": "text/plain", "offset": "23166", "digest": "5S2OB6LK7EHO74WNBNVLNE6ZBB5VRYTI", "status": "200", "length": "818", "mime": "text/plain"
    "urlkey": "pt,gov,academiaportuguesadahistoria)/", "timestamp": "20190218105706", "url": "https://academiaportuguesadahistoria.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247484928.52/warc/CC-MAIN-20190218094308-20190218120308-00509.warc.gz", "mime-detected": "text/html", "offset": "498335094", "digest": "EQOJY7DY2YL752S6QCRXLGNDTELPYLD3", "languages": "por", "status": "200", "length": "10240", "mime": "text/html", "charset": "UTF-8"









    share|improve this question


























      1












      1








      1








      so i have the following code



      import json

      with open("output.json") as f:
      data = json.loads(f.read())
      print(data[0]['url'])


      the thing is i get the following errors when i try to give it a file to process



      Traceback (most recent call last):
      File "C:/Users/pedre/PycharmProjects/app_pdi/app_pdi.py", line 6, in <module>
      data = json.loads(f.read())
      File "C:UserspedreAppDataLocalProgramsPythonPython37-32libjson__init__.py", line 348, in loads
      return _default_decoder.decode(s)
      File "C:UserspedreAppDataLocalProgramsPythonPython37-32libjsondecoder.py", line 340, in decode
      raise JSONDecodeError("Extra data", s, end)
      json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 408)


      i am using PyCharm to write my code, can some one help me ? i am quite new to Python so please be nice xD



      EDIT1:



      my JSON file has the following structure:



      "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8"
      "urlkey": "pt,gov,70ja)/robots.txt", "timestamp": "20190221024013", "url": "http://70ja.gov.pt/robots.txt", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/robotstxt/CC-MAIN-20190221010932-20190221032932-00489.warc.gz", "mime-detected": "text/plain", "offset": "23166", "digest": "5S2OB6LK7EHO74WNBNVLNE6ZBB5VRYTI", "status": "200", "length": "818", "mime": "text/plain"
      "urlkey": "pt,gov,academiaportuguesadahistoria)/", "timestamp": "20190218105706", "url": "https://academiaportuguesadahistoria.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247484928.52/warc/CC-MAIN-20190218094308-20190218120308-00509.warc.gz", "mime-detected": "text/html", "offset": "498335094", "digest": "EQOJY7DY2YL752S6QCRXLGNDTELPYLD3", "languages": "por", "status": "200", "length": "10240", "mime": "text/html", "charset": "UTF-8"









      share|improve this question
















      so i have the following code



      import json

      with open("output.json") as f:
      data = json.loads(f.read())
      print(data[0]['url'])


      the thing is i get the following errors when i try to give it a file to process



      Traceback (most recent call last):
      File "C:/Users/pedre/PycharmProjects/app_pdi/app_pdi.py", line 6, in <module>
      data = json.loads(f.read())
      File "C:UserspedreAppDataLocalProgramsPythonPython37-32libjson__init__.py", line 348, in loads
      return _default_decoder.decode(s)
      File "C:UserspedreAppDataLocalProgramsPythonPython37-32libjsondecoder.py", line 340, in decode
      raise JSONDecodeError("Extra data", s, end)
      json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 408)


      i am using PyCharm to write my code, can some one help me ? i am quite new to Python so please be nice xD



      EDIT1:



      my JSON file has the following structure:



      "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8"
      "urlkey": "pt,gov,70ja)/robots.txt", "timestamp": "20190221024013", "url": "http://70ja.gov.pt/robots.txt", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/robotstxt/CC-MAIN-20190221010932-20190221032932-00489.warc.gz", "mime-detected": "text/plain", "offset": "23166", "digest": "5S2OB6LK7EHO74WNBNVLNE6ZBB5VRYTI", "status": "200", "length": "818", "mime": "text/plain"
      "urlkey": "pt,gov,academiaportuguesadahistoria)/", "timestamp": "20190218105706", "url": "https://academiaportuguesadahistoria.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247484928.52/warc/CC-MAIN-20190218094308-20190218120308-00509.warc.gz", "mime-detected": "text/html", "offset": "498335094", "digest": "EQOJY7DY2YL752S6QCRXLGNDTELPYLD3", "languages": "por", "status": "200", "length": "10240", "mime": "text/html", "charset": "UTF-8"






      python json parsing pycharm






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 22:13







      Pedro Silva

















      asked Mar 25 at 22:29









      Pedro SilvaPedro Silva

      185 bronze badges




      185 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Python parses JSON text to a dictionary.Here is complete answer.



          Your JSON file can be like below:



          [
          "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8",
          "urlkey": "pt,gov,70ja)/robots.txt", "timestamp": "20190221024013", "url": "http://70ja.gov.pt/robots.txt", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/robotstxt/CC-MAIN-20190221010932-20190221032932-00489.warc.gz", "mime-detected": "text/plain", "offset": "23166", "digest": "5S2OB6LK7EHO74WNBNVLNE6ZBB5VRYTI", "status": "200", "length": "818", "mime": "text/plain",
          "urlkey": "pt,gov,academiaportuguesadahistoria)/", "timestamp": "20190218105706", "url": "https://academiaportuguesadahistoria.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247484928.52/warc/CC-MAIN-20190218094308-20190218120308-00509.warc.gz", "mime-detected": "text/html", "offset": "498335094", "digest": "EQOJY7DY2YL752S6QCRXLGNDTELPYLD3", "languages": "por", "status": "200", "length": "10240", "mime": "text/html", "charset": "UTF-8"
          ]


          Parsing such a JSON file in python3:



          import json

          with open("jsonDataFile.json") as f:
          jsonData = json.loads(f.read())
          for array in jsonData:
          for key, value in array.items():
          print("Key:%s Value:%s" % (key,value))


          If your file is not an array of json data:



          "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8"


          Parsing such a JSON file in python3:



          import json

          with open("test3.json") as f:
          jsonData = json.loads(f.read())

          for key, value in jsonData.items():
          print("Key:%s Value:%s" % (key,value))





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347319%2fpython-program-to-read-a-specific-field-in-json-file-outpouting-erros%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Python parses JSON text to a dictionary.Here is complete answer.



            Your JSON file can be like below:



            [
            "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8",
            "urlkey": "pt,gov,70ja)/robots.txt", "timestamp": "20190221024013", "url": "http://70ja.gov.pt/robots.txt", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/robotstxt/CC-MAIN-20190221010932-20190221032932-00489.warc.gz", "mime-detected": "text/plain", "offset": "23166", "digest": "5S2OB6LK7EHO74WNBNVLNE6ZBB5VRYTI", "status": "200", "length": "818", "mime": "text/plain",
            "urlkey": "pt,gov,academiaportuguesadahistoria)/", "timestamp": "20190218105706", "url": "https://academiaportuguesadahistoria.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247484928.52/warc/CC-MAIN-20190218094308-20190218120308-00509.warc.gz", "mime-detected": "text/html", "offset": "498335094", "digest": "EQOJY7DY2YL752S6QCRXLGNDTELPYLD3", "languages": "por", "status": "200", "length": "10240", "mime": "text/html", "charset": "UTF-8"
            ]


            Parsing such a JSON file in python3:



            import json

            with open("jsonDataFile.json") as f:
            jsonData = json.loads(f.read())
            for array in jsonData:
            for key, value in array.items():
            print("Key:%s Value:%s" % (key,value))


            If your file is not an array of json data:



            "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8"


            Parsing such a JSON file in python3:



            import json

            with open("test3.json") as f:
            jsonData = json.loads(f.read())

            for key, value in jsonData.items():
            print("Key:%s Value:%s" % (key,value))





            share|improve this answer





























              1














              Python parses JSON text to a dictionary.Here is complete answer.



              Your JSON file can be like below:



              [
              "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8",
              "urlkey": "pt,gov,70ja)/robots.txt", "timestamp": "20190221024013", "url": "http://70ja.gov.pt/robots.txt", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/robotstxt/CC-MAIN-20190221010932-20190221032932-00489.warc.gz", "mime-detected": "text/plain", "offset": "23166", "digest": "5S2OB6LK7EHO74WNBNVLNE6ZBB5VRYTI", "status": "200", "length": "818", "mime": "text/plain",
              "urlkey": "pt,gov,academiaportuguesadahistoria)/", "timestamp": "20190218105706", "url": "https://academiaportuguesadahistoria.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247484928.52/warc/CC-MAIN-20190218094308-20190218120308-00509.warc.gz", "mime-detected": "text/html", "offset": "498335094", "digest": "EQOJY7DY2YL752S6QCRXLGNDTELPYLD3", "languages": "por", "status": "200", "length": "10240", "mime": "text/html", "charset": "UTF-8"
              ]


              Parsing such a JSON file in python3:



              import json

              with open("jsonDataFile.json") as f:
              jsonData = json.loads(f.read())
              for array in jsonData:
              for key, value in array.items():
              print("Key:%s Value:%s" % (key,value))


              If your file is not an array of json data:



              "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8"


              Parsing such a JSON file in python3:



              import json

              with open("test3.json") as f:
              jsonData = json.loads(f.read())

              for key, value in jsonData.items():
              print("Key:%s Value:%s" % (key,value))





              share|improve this answer



























                1












                1








                1







                Python parses JSON text to a dictionary.Here is complete answer.



                Your JSON file can be like below:



                [
                "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8",
                "urlkey": "pt,gov,70ja)/robots.txt", "timestamp": "20190221024013", "url": "http://70ja.gov.pt/robots.txt", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/robotstxt/CC-MAIN-20190221010932-20190221032932-00489.warc.gz", "mime-detected": "text/plain", "offset": "23166", "digest": "5S2OB6LK7EHO74WNBNVLNE6ZBB5VRYTI", "status": "200", "length": "818", "mime": "text/plain",
                "urlkey": "pt,gov,academiaportuguesadahistoria)/", "timestamp": "20190218105706", "url": "https://academiaportuguesadahistoria.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247484928.52/warc/CC-MAIN-20190218094308-20190218120308-00509.warc.gz", "mime-detected": "text/html", "offset": "498335094", "digest": "EQOJY7DY2YL752S6QCRXLGNDTELPYLD3", "languages": "por", "status": "200", "length": "10240", "mime": "text/html", "charset": "UTF-8"
                ]


                Parsing such a JSON file in python3:



                import json

                with open("jsonDataFile.json") as f:
                jsonData = json.loads(f.read())
                for array in jsonData:
                for key, value in array.items():
                print("Key:%s Value:%s" % (key,value))


                If your file is not an array of json data:



                "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8"


                Parsing such a JSON file in python3:



                import json

                with open("test3.json") as f:
                jsonData = json.loads(f.read())

                for key, value in jsonData.items():
                print("Key:%s Value:%s" % (key,value))





                share|improve this answer















                Python parses JSON text to a dictionary.Here is complete answer.



                Your JSON file can be like below:



                [
                "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8",
                "urlkey": "pt,gov,70ja)/robots.txt", "timestamp": "20190221024013", "url": "http://70ja.gov.pt/robots.txt", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/robotstxt/CC-MAIN-20190221010932-20190221032932-00489.warc.gz", "mime-detected": "text/plain", "offset": "23166", "digest": "5S2OB6LK7EHO74WNBNVLNE6ZBB5VRYTI", "status": "200", "length": "818", "mime": "text/plain",
                "urlkey": "pt,gov,academiaportuguesadahistoria)/", "timestamp": "20190218105706", "url": "https://academiaportuguesadahistoria.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247484928.52/warc/CC-MAIN-20190218094308-20190218120308-00509.warc.gz", "mime-detected": "text/html", "offset": "498335094", "digest": "EQOJY7DY2YL752S6QCRXLGNDTELPYLD3", "languages": "por", "status": "200", "length": "10240", "mime": "text/html", "charset": "UTF-8"
                ]


                Parsing such a JSON file in python3:



                import json

                with open("jsonDataFile.json") as f:
                jsonData = json.loads(f.read())
                for array in jsonData:
                for key, value in array.items():
                print("Key:%s Value:%s" % (key,value))


                If your file is not an array of json data:



                "urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8"


                Parsing such a JSON file in python3:



                import json

                with open("test3.json") as f:
                jsonData = json.loads(f.read())

                for key, value in jsonData.items():
                print("Key:%s Value:%s" % (key,value))






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 28 at 21:52

























                answered Mar 25 at 23:18









                kemalturgulkemalturgul

                404 bronze badges




                404 bronze badges


















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347319%2fpython-program-to-read-a-specific-field-in-json-file-outpouting-erros%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현