How to use JSON from Jekyll _data directory?

According to Jekyll docs, you can access the YAML, JSON and CSV files in a directory _datausing {{ site.data.filename }}.

I have a valid geoJson file with point functions called chapters.json. I can access the file, but I see some strange characters when I use this file in my javascript.

chapters.json excerpt:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "title": "MaptimeBER"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          13.391,
          52.521
        ]
      }
    },
    {...}
  ]
}

For example, when Jekyll processes the following: var chapters = {{ site.data.chapters }};

Output Javascript:

var chapters = {"type"=>"FeatureCollection", "features"=>[{"type"=>"Feature", "properties"=> ...

My question is: why does the colon separating key-value pairs change to =>? This results in my javascript error.

+4
source share
1 answer

jsonify, Hash Array JSON:

var chapters = {{ site.data.chapters | jsonify }};
+9

All Articles