title: JSON.NET and arrays using LINQ
body: <p>I looked at this <a href="https://stackoverflow.com/questions/401756/parsing-json-using-json-net">Parsing JSON using Json.net</a> question and answer and it's close to what I need. The critical difference Is that I need to parse an array of x,y pairs that form one or more lines per record. Here's an example of my input</p>
  
  <pre><code>{
  "displayFieldName" : "FACILITYID", 
  "fieldAliases" : {
  "FACILITYID" : "Facility Identifier", 
  }, 
  "geometryType" : "esriGeometryPolyline", 
  "spatialReference" : {
    "wkid" : 4326
  }, 
  "features" : [
  {
    "attributes" : {
      "FACILITYID" : "", 
      "OBJECTID" : 1, 
    }, 
    "geometry" : 
    {
      "paths" : 
      [
        [
          [-80.3538239379999, 27.386884271], 
          [-80.3538100319999, 27.3868901900001], 
          [-80.3538157239999, 27.3869008510001]
        ]
      ]
    }
  }, 
  {
    "attributes" : {
      "FACILITYID" : "", 
      "OBJECTID" : 2, 
    }, 
    "geometry" : 
    {
      "paths" : 
      [
        [
          [-80.3538239379999, 27.386884271], 
          [-80.3538295849999, 27.3868948420001]
        ]
      ]
    }
  }
  ]
  }
  </code></pre>
  
  <p>(Check out <a href="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/WaterTemplate/WaterDistributionNetwork/MapServer/9/query?outFields=" rel="nofollow noreferrer">http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/WaterTemplate/WaterDistributionNetwork/MapServer/9/query?outFields=</a>*&amp;where=OBJECTID%3C20&amp;f=pjson for the full listing)</p>
  
  <p>What I need to do is parse the ["features"]["geometry"]["paths"] arrays in to lines composed of x,y pairs. Here is how I'm getting all of the paths (one per "record" as in the features array):</p>
  
  <pre><code>var allPaths = from p in jsonObject["features"].Children()["geometry"]
                 select p["paths"];
  </code></pre>
  
  <p>That gives me my paths, from which I can then process each point array in turn:</p>
  
  <pre><code>foreach (var eachPolylineInPath in allPaths)
  {
    IEnumerable&lt;Point&gt; linePoints = from line in eachPolylineInPath.Children()
                                    select new Point(
                                                    (double) line[0],
                                                    (double) line[1],
                                                    double.NaN);
  }
  </code></pre>
  
  <p>That's where I get stuck. I'm trying various casts from JArray and LINQ-y statements but keep getting null results or exceptions to the tune of JProperty child values cannot be accessed.</p>
  
  <p>Hopefully someone has already dealt with converting arrays of arrays in JSON.NET using LINQ and can explain the stupid mistake I must be making, or the obvious answer I'm failing to see.</p>