markdown-to-json


Namemarkdown-to-json JSON
Version 2.1.0 PyPI version JSON
download
home_pagehttps://github.com/njvack/markdown_to_json
SummaryMarkdown to dict and json deserializer
upload_time2023-06-04 16:56:55
maintainer
docs_urlNone
authorNathan Vack
requires_python>=3.6.2
licenseMIT
keywords serializer deserializer markdown
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.

## Why would you want to do this?

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 datastructure to extract data-like structures from a Markdown document.

This tool was built to allow easy 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 <njvack@freshforever.net> 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": "",
    "docs_url": null,
    "requires_python": ">=3.6.2",
    "maintainer_email": "",
    "keywords": "serializer,deserializer,markdown",
    "author": "Nathan Vack",
    "author_email": "njvack@wisc.edu",
    "download_url": "https://files.pythonhosted.org/packages/25/50/61b5710d3201ee9e14f599f06d886dba3958423b99428179d3f6f7206a63/markdown_to_json-2.1.0.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## Why would you want to do this?\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 datastructure to extract data-like structures from a Markdown document.\n\nThis tool was built to allow easy 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 <njvack@freshforever.net> 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",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Markdown to dict and json deserializer",
    "version": "2.1.0",
    "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": "cebf4ac898c83ec46fa9376a8bce125057e9b991760efbe7631813631ed3aade",
                "md5": "013e1c9118b543b53c4b25c57d039ece",
                "sha256": "44a17e3ff42af4f049fa2a6a86efbe30e27dcf8401c7ad1772b97b2d396d88f8"
            },
            "downloads": -1,
            "filename": "markdown_to_json-2.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "013e1c9118b543b53c4b25c57d039ece",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.2",
            "size": 52336,
            "upload_time": "2023-06-04T16:56:54",
            "upload_time_iso_8601": "2023-06-04T16:56:54.168697Z",
            "url": "https://files.pythonhosted.org/packages/ce/bf/4ac898c83ec46fa9376a8bce125057e9b991760efbe7631813631ed3aade/markdown_to_json-2.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "255061b5710d3201ee9e14f599f06d886dba3958423b99428179d3f6f7206a63",
                "md5": "b234e1c59a091bf668f41b3b5faa5877",
                "sha256": "ea02313f7c5e8d05033d7a2b4e7c891246bc8f6391e1681760579687e6b0ba68"
            },
            "downloads": -1,
            "filename": "markdown_to_json-2.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b234e1c59a091bf668f41b3b5faa5877",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.2",
            "size": 50676,
            "upload_time": "2023-06-04T16:56:55",
            "upload_time_iso_8601": "2023-06-04T16:56:55.743131Z",
            "url": "https://files.pythonhosted.org/packages/25/50/61b5710d3201ee9e14f599f06d886dba3958423b99428179d3f6f7206a63/markdown_to_json-2.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-04 16:56:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "njvack",
    "github_project": "markdown_to_json",
    "github_not_found": true,
    "lcname": "markdown-to-json"
}
        
Elapsed time: 0.07393s