How to read the JSON front matter of a Hugo markdown file with python?

I am looking for a nice code snippet or module to read the JSON part of the markdown file. It should detect the length of the JSON block automatically.

I am sure this is already solved in a clean way and I do not want to reinvent the wheel but could not find a ready to use solution yet.

This question has been asked before, it seems – my favorite search engine easily finds an answer from 2018. That has nothing to do with Hugo, it’s a Python issue.

I agree that it’s not a pure Hugo question. But it’s wrong to say that it has nothing to do with Hugo. Is is even an FAQ. In the Meantime I found “from frontmatter.default_handlers import JSONHandler” However I am not sure, if this is the best way to go.

There’s nothing special with Hugo frontmatter. And there’s no official way to utilize a python library from hugo. So

Your question asked is a generic one. So a pyhthon forum might be a better choice to ask

If you have a specific Use case/problem for Hugo please elaborate.

Btw easily found with first hit: python-frontmatter · PyPI

3 Likes

Thank you. That is useful. I was not aware that JSON frontmatter is a thing outside of Hugo. I will try my luck with this library then.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.