0

Below Python code I am using that throws error, i tried readlines, json.loads as well but that doesnt seem to woork as well

with open('/Users/akshayarora/PythonCodes/Capstone1/Delhi.json') as data_file: 
    provinces_json = json.load(data_file)
var dataset = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "City": "Delhi",
        "State": "Delhi"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          77.266052,
          28.68161
        ]
      }
           ]
    }
           }

Akshay
  • 81
  • 2
  • 2
  • 9
  • --> 355 raise JSONDecodeError("Expecting value", s, err.value) from None 356 return obj, end JSONDecodeError: Expecting value: line 1 column 1 (char 0) I tries json.loads as well as but its also throwing error. – Akshay Feb 27 '20 at 19:02
  • 1
    Please provide a sample of what the JSON looks like. It's most likely invalid. – Wondercricket Feb 27 '20 at 19:02
  • It looks like: var dataset = { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "City": "Delhi", "State": "Delhi" }, "geometry": { "type": "Point", "coordinates": [ 77.266052, 28.68161 ] } }, { "type": "Feature", "properties": { "City": "Delhi", "State": "Delhi" }, "geometry": { "type": "Point", "coordinates": [ 77.266052, 28.68161 ] } } – Akshay Feb 27 '20 at 19:04
  • like these i have many values, i have provided sample above – Akshay Feb 27 '20 at 19:05
  • Please edit your question to include the JSON. Format the JSON as code, so that it's easier to read. Also, look for non-printing characters at the start of the file. – Jim DeLaHunt Feb 27 '20 at 19:07
  • Please share the entire error message as well as a [mcve], in your post itself. – AMC Feb 27 '20 at 19:16
  • Does this answer your question? [JSONDecodeError: Expecting value: line 1 column 1 (char 0)](https://stackoverflow.com/questions/16573332/jsondecodeerror-expecting-value-line-1-column-1-char-0) – AMC Feb 27 '20 at 19:16
  • @AMC - i tries all those mentioned in the link above but same error is coming – Akshay Feb 27 '20 at 19:22
  • @Akshay We still don't have the necessary information to reproduce this, so I'm not sure what you expect us to be able to do. – AMC Feb 27 '20 at 19:25
  • TRY WITH THIS JSON: – Akshay Feb 27 '20 at 19:30
  • var dataset = { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "City": "Delhi", "State": "Delhi" }, "geometry": { "type": "Point", "coordinates": [ 77.266052, 28.68161 ] } ] } } – Akshay Feb 27 '20 at 19:30
  • Add that to your post, not as a comment, as others have already mentioned. Also, that looks like JavaScript. – AMC Feb 27 '20 at 19:32
  • That still isn't an [mcve]. **The code is incomplete, the data is both invalid JSON and invalid Python.** (it looks like JS) – AMC Feb 27 '20 at 20:23

1 Answers1

1

Thats not JSON... JSON is not javascript, it is a way of serializing javascript (or thats what it was designed for). Your var dataset = { is wrong, JSON is not a programming language its a way of storing data structures

Also your JSON is malformed. Your close bracket is in the wrong place

 {"features": [ ... /* HERE */ } /* NOT HERE (where you currently have it) }

(Note comments are not supported in the JSON standard, this is just for show)

Object object
  • 1,939
  • 10
  • 19
  • I have provided the sample only, so its missing here. in actual file its present – Akshay Feb 27 '20 at 19:13
  • Are you sure? Your saying when you copied it you missed a bracket within it another bracket?? Have you tried this to see if it works? – Object object Feb 27 '20 at 19:15
  • @Akshay _I have provided the sample only, so its missing here. in actual file its present_ Then it's not a [mcve], right? – AMC Feb 27 '20 at 19:16
  • *reproducable* if your code does not actually show the issue then its pointless. This answer is correct for the code you provided, please try it and/or fix your question – Object object Feb 27 '20 at 19:19
  • @AMC -I have provided sample json through this i am able to reproduce it – Akshay Feb 27 '20 at 19:39
  • @Akshay As I already wrote in another comment, that isn't valid JSON, nor is it even valid Python. We're still missing the entire error message, and the code looks incomplete. – AMC Feb 27 '20 at 19:41
  • @Akshay What changed? I can't see any difference. – AMC Feb 27 '20 at 20:02