# Markdown to JSON converter
## Description
A simple tool to convert Markdown (CommonMark dialect) data into JSON. It uses headings as JSON keys, and the stuff following headings as values. Lists are turned into arrays. Higher heading values yield nested JSON keys.
## Is this for me?
If you have to ask that question, it probably isn't. Here are some cases where I'd recommend something else:
### I want to parse arbitrary Markdown
In this case, I'd recommend the excellent [markdown-it-py](https://github.com/executablebooks/markdown-it-py)
### I want to hand-write nested structures but hate writing JSON by hand
In this case, [TOML](https://toml.io/en/) might be what you're looking for. [Python support is built-in as of 3.11](https://docs.python.org/3/library/tomllib.html). If I had known of TOML, I would never have written this package.
### Nope, those situations don't cover me; I really want to parse Markdown into data
If you don't mind the loss of fidelity to the exact Markdown Document Object Model (DOM), you can get a simple python or json data structure to extract data-like structures from a subset of Markdown documents.
This tool was built to allow easier creation of dataset descriptions for the [Brain Imaging Data Structure](http://bids.neuroimaging.io/) data sharing specification.
## Installation
Non isolated install from pypi
```bash
pip install markdown-to-json
md_to_json --help
```
Isolated install with pipx if you only want the CLI
```bash
pipx install markdown-to-json
md_to_json --help
```
Install bleeding edge from github
```bash
pip install git+https://github.com/njvack/markdown-to-json/
python -m markdown_to_json --help
```
```bash
git clone https://github.com/njvack/markdown-to-json.git
cd markdown_to_json
./setup.py install
```
The package has no external requirements and has been tested python 3.6+.
Please use version 1 or 1.1 for python 2.x.
## CLI Usage, `md_to_json`
```
Translate Markdown into JSON.
Usage:
md_to_json [options] <markdown_file>
md_to_json -h | --help
Options:
-h --help Show this screen
--version Print version number
-o <file> Save output to a file instead of stdout
-i <val> Indent nested JSON by this amount. Use a negative number for
most compact possible JSON. the [default: 2]
```
## Programmatic usage
```python
import markdown_to_json
value = """
# Nested List
* Item 1
* Item 1.1
* Item 2
"""
# The simple way:
dictified = markdown_to_json.dictify(value)
assert dictified == {'Nested List': ['Item 1', ['Item 1.1'], 'Item 2']}
# Or, if you want a json string
jsonified = markdown_to_json.jsonify(value)
assert jsonified == """{"Nested List": ["Item 1", ["Item 1.1"], "Item 2"]}"""
```
This translates a Markdown document into JSON as described in the example below.
## Example
The Markdown:
```markdown
# Description
This is an example file
# Authors
* Nate Vack
* Vendor Packages
* docopt
* CommonMark-py
# Versions
## Version 1
Here's something about Version 1; I said "Hooray!"
## Version 2
Here's something about Version 2
```
will translate to the JSON:
```json
{
"Description": "This is an example file",
"Authors": ["Nate Vack", "Vendor Packages", ["docopt", "CommonMark-py"]],
"Versions": {
"Version 1": "Here's something about Version 1; I said \"Hooray!\"",
"Version 2": "Here's something about Version 2"
}
}
```
## Credits
`markdown_to_json` was written by [Nate Vack](https://github.com/njvack) at the Center for Healthy Minds at the University of Wisconsin–Madison.
Maintenance development by [Matthew Martin](https://github.com/matthewdeanmartin/)
This tool ships a few really excellent tools in its `vendor` directory:
[docopt](https://github.com/docopt/docopt) is copyright (c) 2012 Vladimir Keleshev, <vladimir@keleshev.com>
Upgraded to docopt-ng.
[CommonMark-py](https://github.com/rolandshoemaker/CommonMark-py) is copyright Copyright (c) 2014, Bibek Kafle and Roland Shoemaker.
Cannot upgrade to 0.6.0 because of breaking changes in AST.
Raw data
{
"_id": null,
"home_page": "https://github.com/njvack/markdown-to-json",
"name": "markdown-to-json",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "serializer, deserializer, markdown",
"author": "Nathan Vack",
"author_email": "njvack@wisc.edu",
"download_url": "https://files.pythonhosted.org/packages/7d/b7/e333b0c8d3447b0e55a32a57beb15d456e33ea605312bfebb6e3dba29205/markdown_to_json-2.1.2.tar.gz",
"platform": null,
"description": "# Markdown to JSON converter\n\n## Description\n\nA simple tool to convert Markdown (CommonMark dialect) data into JSON. It uses headings as JSON keys, and the stuff following headings as values. Lists are turned into arrays. Higher heading values yield nested JSON keys.\n\n## Is this for me?\n\nIf you have to ask that question, it probably isn't. Here are some cases where I'd recommend something else:\n\n### I want to parse arbitrary Markdown\n\nIn this case, I'd recommend the excellent [markdown-it-py](https://github.com/executablebooks/markdown-it-py)\n\n### I want to hand-write nested structures but hate writing JSON by hand\n\nIn this case, [TOML](https://toml.io/en/) might be what you're looking for. [Python support is built-in as of 3.11](https://docs.python.org/3/library/tomllib.html). If I had known of TOML, I would never have written this package.\n\n### Nope, those situations don't cover me; I really want to parse Markdown into data\n\nIf you don't mind the loss of fidelity to the exact Markdown Document Object Model (DOM), you can get a simple python or json data structure to extract data-like structures from a subset of Markdown documents.\n\nThis tool was built to allow easier creation of dataset descriptions for the [Brain Imaging Data Structure](http://bids.neuroimaging.io/) data sharing specification.\n\n## Installation\n\nNon isolated install from pypi\n```bash\npip install markdown-to-json\nmd_to_json --help\n```\n\nIsolated install with pipx if you only want the CLI\n```bash\npipx install markdown-to-json\nmd_to_json --help\n```\n\nInstall bleeding edge from github\n```bash\npip install git+https://github.com/njvack/markdown-to-json/\npython -m markdown_to_json --help\n```\n\n```bash\ngit clone https://github.com/njvack/markdown-to-json.git\ncd markdown_to_json\n./setup.py install\n```\n\nThe package has no external requirements and has been tested python 3.6+.\n\nPlease use version 1 or 1.1 for python 2.x.\n\n## CLI Usage, `md_to_json`\n\n```\nTranslate Markdown into JSON.\n\nUsage:\n md_to_json [options] <markdown_file>\n md_to_json -h | --help\n\nOptions:\n -h --help Show this screen\n --version Print version number\n -o <file> Save output to a file instead of stdout\n -i <val> Indent nested JSON by this amount. Use a negative number for\n most compact possible JSON. the [default: 2]\n```\n\n## Programmatic usage\n```python\nimport markdown_to_json\nvalue = \"\"\"\n# Nested List\n\n* Item 1\n * Item 1.1\n* Item 2\n\"\"\"\n\n# The simple way:\ndictified = markdown_to_json.dictify(value)\nassert dictified == {'Nested List': ['Item 1', ['Item 1.1'], 'Item 2']}\n\n# Or, if you want a json string\njsonified = markdown_to_json.jsonify(value)\nassert jsonified == \"\"\"{\"Nested List\": [\"Item 1\", [\"Item 1.1\"], \"Item 2\"]}\"\"\"\n```\n\nThis translates a Markdown document into JSON as described in the example below.\n\n## Example\n\nThe Markdown:\n\n```markdown\n# Description\n\nThis is an example file\n\n# Authors\n\n* Nate Vack\n* Vendor Packages\n * docopt\n * CommonMark-py\n\n# Versions\n\n## Version 1\n\nHere's something about Version 1; I said \"Hooray!\"\n\n## Version 2\n\nHere's something about Version 2\n```\n\nwill translate to the JSON:\n\n```json\n{\n \"Description\": \"This is an example file\",\n \"Authors\": [\"Nate Vack\", \"Vendor Packages\", [\"docopt\", \"CommonMark-py\"]],\n \"Versions\": {\n \"Version 1\": \"Here's something about Version 1; I said \\\"Hooray!\\\"\",\n \"Version 2\": \"Here's something about Version 2\"\n }\n}\n```\n\n## Credits\n\n`markdown_to_json` was written by [Nate Vack](https://github.com/njvack) at the Center for Healthy Minds at the University of Wisconsin\u2013Madison.\n\nMaintenance development by [Matthew Martin](https://github.com/matthewdeanmartin/)\n\nThis tool ships a few really excellent tools in its `vendor` directory:\n\n[docopt](https://github.com/docopt/docopt) is copyright (c) 2012 Vladimir Keleshev, <vladimir@keleshev.com>\n\nUpgraded to docopt-ng.\n\n[CommonMark-py](https://github.com/rolandshoemaker/CommonMark-py) is copyright Copyright (c) 2014, Bibek Kafle and Roland Shoemaker.\n\nCannot upgrade to 0.6.0 because of breaking changes in AST.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Markdown to dict and json deserializer",
"version": "2.1.2",
"project_urls": {
"Bug Tracker": "https://github.com/njvack/markdown-to-json/issues",
"Change Log": "https://github.com/njvack/markdown-to-json/blob/main/CHANGELOG.md",
"Documentation": "https://github.com/njvack/markdown-to-json",
"Homepage": "https://github.com/njvack/markdown-to-json",
"Repository": "https://github.com/njvack/markdown-to-json"
},
"split_keywords": [
"serializer",
" deserializer",
" markdown"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0b0aaffeb612dcd97a6842e59b118b7facd6cfaf1dc7509ad7a4d986c974d2da",
"md5": "3010a5883ca571ec13853fe7910b1f87",
"sha256": "bda2c90082d93a6da051dbeda2ab46d79da5ed0590f5a5abba6c58dbc751be1b"
},
"downloads": -1,
"filename": "markdown_to_json-2.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3010a5883ca571ec13853fe7910b1f87",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 52645,
"upload_time": "2024-09-20T20:38:56",
"upload_time_iso_8601": "2024-09-20T20:38:56.140476Z",
"url": "https://files.pythonhosted.org/packages/0b/0a/affeb612dcd97a6842e59b118b7facd6cfaf1dc7509ad7a4d986c974d2da/markdown_to_json-2.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7db7e333b0c8d3447b0e55a32a57beb15d456e33ea605312bfebb6e3dba29205",
"md5": "a9d69a187235c1db116c4cec9540f543",
"sha256": "8fa5b4191c74a20297fe2622ee6dd202f82448d025af9c837732d45a64551d01"
},
"downloads": -1,
"filename": "markdown_to_json-2.1.2.tar.gz",
"has_sig": false,
"md5_digest": "a9d69a187235c1db116c4cec9540f543",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 51536,
"upload_time": "2024-09-20T20:38:57",
"upload_time_iso_8601": "2024-09-20T20:38:57.557823Z",
"url": "https://files.pythonhosted.org/packages/7d/b7/e333b0c8d3447b0e55a32a57beb15d456e33ea605312bfebb6e3dba29205/markdown_to_json-2.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-20 20:38:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "njvack",
"github_project": "markdown-to-json",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "markdown-to-json"
}