title: Reading JSON file from R
body: <p>I try reading a <a href="http://www.json.org/" rel="nofollow noreferrer">JSON</a> file from R using <a href="http://cran.r-project.org/web/packages/rjson/index.html" rel="nofollow noreferrer">rjson</a> but keep getting errors. I validated the JSON file using various online validators. Here is the content of the JSON file:</p>
  
  <pre><code>{
     "scenarios": [
        {
           "files": {
              "type1": "/home/blah/Desktop/temp/scen_0.type1",
              "type2": "/home/blah/Desktop/temp/scen_0.type2"
           },
           "ID": "scen_0",
           "arr": [],
           "TypeToElementStatsFilename": {
              "type1": "/home/blah/Desktop/temp/scen_0.type1.elements",
              "type2": "/home/blah/Desktop/temp/scen_0.type2.elements"
           }
        }
     ],
     "randomSeed": "39327314969888",
     "zone": {
        "length": 1000000,
        "start": 1
     },
     "instanceFilename": "/home/blah/bloo/data/XY112.zip",
     "txtFilename": "/home/blah/bloo/data/XY112.txt",
     "nSimulations": 2,
     "TypeTodbFilename": {
        "type1": "/home/blah/bloo/data/map.type1.oneAmb.XY112.out"
     },
     "arr": {
        "seg11": {
           "length": 1000,
           "start": 147000
        },
        "seg12": {
           "length": 1000,
           "start": 153000
        },
        "seg5": {
           "length": 1000,
           "start": 145000
        },
        "seg6": {
           "length": 1000,
           "start": 146000
        },
        "seg1": {
           "length": 100,
           "start": 20000
        }
     },
     "outPath": "/home/blah/Desktop/temp",
     "instanceID": "XY112",
     "arrIds": [
        "seg5",
        "seg6",
        "seg1",
        "seg11",
        "seg12"
     ],
     "truth": {
        "files": {
           "type1": "/home/blah/Desktop/temp/truth.type1",
           "type2": "/home/blah/Desktop/temp/truth.type2"
        },
        "ID": "truth",
        "TypeToElementStatsFilename": {
           "type1": "/home/blah/Desktop/temp/truth.type1.elements",
           "type2": "/home/blah/Desktop/temp/truth.type2.elements"
        }
     }
  }
  </code></pre>
  
  <p>And the error:</p>
  
  <pre><code>&gt; json_file &lt;- "~/json"
  &gt; json_data &lt;- fromJSON(paste(readLines(json_file), collapse=""))
  Error in fromJSON(paste(readLines(json_file), collapse = "")) :
    unexpected character: :
  </code></pre>