Skip to main content

Convert json value to markdown

Project description

对任意json格式的数据,转换成markdown格式的文本

安装

pip install jsonvalue2markdown

用法示例

from jsonvalue2markdown import JsonValueToMarkdown
json_value = {
        "title": "标题",
        "context": {
            "subtitle": "副标题",
            "context1": "内容1",
            "context2": "内容2",
            "context6": [
                "内容3",
                "内容4",
                {
                    "context7": "内容5",
                    "context8": "内容6",
                },
                {"context9": "内容10"}
            ],
            "context3": "内容7",
            "context4": "https://www.test.demo.jpg",
        },
    }

mapping_dict = {
        "title": "h1",
        "subtitle": "h2",
        "context1": "p",
        "context2": "li",
        "context7": "li",
        "context8": "li",
        "context3": "li",
        "context4": "img",
        "context9": "p",
    }

markdown = JsonValueToMarkdown(
        json_value=json_value,
        mapping_dict=mapping_dict,
        title_level=3,
    ).convert()
print(markdown)

参数说明

参数 说明
json_value 需要转换为markdown格式的json数据
mapping_dict json数据中的key与markdown中的标签的映射关系
title_level 标题的级别,从1开始,最大为6

输出结果

#标题
##副标题
内容1

  * 内容2
内容3

内容4

  * 内容5
  * 内容6
内容10

  * 内容7
![](https://www.test.demo.jpg)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonvalue2markdown-0.0.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

jsonvalue2markdown-0.0.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file jsonvalue2markdown-0.0.1.tar.gz.

File metadata

  • Download URL: jsonvalue2markdown-0.0.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for jsonvalue2markdown-0.0.1.tar.gz
Algorithm Hash digest
SHA256 68ffedf7293ea080a4e935f13341b36728a6b38e435228d15e96b833abc8c621
MD5 918d949c1d956fec0028bb99095f1e49
BLAKE2b-256 24bb8efb1f28fc2791a9abafc23a5bf5c697d64b211d300786c40f0f2663c2af

See more details on using hashes here.

File details

Details for the file jsonvalue2markdown-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for jsonvalue2markdown-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce952c32a4bdbffc3dcbbddca5c96107f71e71525ec01521f4aa2b85931894ee
MD5 e81b572609b49bae6eddb74149a27447
BLAKE2b-256 01e6fbb24e6ef16812a2c9cec07b76f1670b5e381a3c26266c1eedeb764358af

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page