According to the Jekyll docs you can access YAML, JSON, and CSV files in the _data
directory using {{ site.data.filename }}
.
I have a valid geoJson file of point features called chapters.json
. I'm able to access the file, but I'm seeing some strange characters when I use the 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 }};
The output Javascript is:
var chapters = {"type"=>"FeatureCollection", "features"=>[{"type"=>"Feature", "properties"=> ...
My question is, why does the colon separating key-value pairs change to =>
? It's causing my javascript to error out.
Use the jsonify filter, it convert Hash or Array to JSON :
var chapters = {{ site.data.chapters | jsonify }};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With