I'm attempting to create a JSON feed on a GitHub Pages site, and I'm having issues with JSON because I'm not sure how I can properly encode it using Jekyll. Is there an extension or method I can use?
feed: http://iowacodecamp.github.io/sessions.json
source: https://github.com/IowaCodeCamp/iowacodecamp.github.io/blob/master/sessions.json
Note the double quotes in the data.
Your json doesn't validate because of the coma after the last session.
If you don't want a coma after the last session, use forloop liquid object around
{
"sessions": {
"session": [{% for session_hash in site.data.sessions %}{% assign session = session_hash[1] %}
{
"title": {{ session.title | jsonify }},
"description": {{ session.description | jsonify }},
"level": {{ session.level | jsonify }},
"author": {
"name": {{ session.speaker.name | jsonify }},
"slug": {{ session.speaker.slug | jsonify }}
}
}{% if forloop.last == false %}, {% endif %}{% endfor %}
]
}
}
Question : You have multiples sessions in your datas but they are all in the same session array. Do you really need this key ? Maybe you can just do :
{
"sessions": [{% for session in site.data.sessions %}
{{ session[1] | jsonify }}{% if forloop.last == false %}, {% endif %}{% endfor %}
]
}
Which also validates.
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