V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
chinazz
V2EX  ›  Python

Python 有没有这样的三方库?通过定义好的 json 模板,传入数据,生成新的 json

  •  
  •   chinazz ·
    chinazhenzhen · Dec 3, 2019 · 5019 views
    This topic created in 2338 days ago, the information mentioned may be changed or developed.

    Python 有没有这样的三方库?通过定义好的 json 模板( json 模板可存储),传入数据,生成新的 json

    现在不清楚用什么方法构建 json 模板。 也网上找了一些方法?比如利用 jinja2 之类的,不知道有没有更好的方法。

    15 replies    2024-03-18 14:56:12 +08:00
    inorilzy
        1
    inorilzy  
       Dec 3, 2019
    自己写,想生成啥样生成啥样,也不是很难吧。
    danbai
        2
    danbai  
    PRO
       Dec 3, 2019
    写个类 然后存入数据 转成 json
    Trim21
        3
    Trim21  
       Dec 3, 2019
    pydantic?
    Vegetable
        4
    Vegetable  
       Dec 3, 2019
    完全看不懂是要干什么...json 模板?json 还需要模板吗?那不就是写好了序列化方法的数据结构吗?实际上不就是类吗
    chinazz
        5
    chinazz  
    OP
       Dec 3, 2019
    大概就是 A 同学想自己定义一个代码或者 json 模板。我们这边代码逻辑不关注他们的模板长什么样子,向模板里边填入数据。
    danbai
        6
    danbai  
    PRO
       Dec 3, 2019
    json 不知道数据格式怎么填数据 难道你要返回个 map 吗
    至少你得拿到 A 同学的 json 格式 然后根据格式生成或写个类 然后代码根据类字段填值返回 json
    ddzzhen
        7
    ddzzhen  
       Dec 3, 2019 via Android
    难道不是一个函数就搞定了?
    neoblackcap
        9
    neoblackcap  
       Dec 3, 2019
    json 模板不行,json schema 可以
    chinazz
        10
    chinazz  
    OP
       Dec 3, 2019
    @eGlhb2Jhb2Jhbw 哇!就是这种。不过他们需要那种正反双向都支持的,不仅能加载成 json,还能从 json 加载出数据。
    holajamc
        11
    holajamc  
       Dec 3, 2019
    jinjia2?
    superrichman
        12
    superrichman  
       Dec 3, 2019
    用自带的 json 库再加 jinja2 就行. 读写都可以
    iamsk
        13
    iamsk  
       Dec 3, 2019
    搜一下 json editor,json schema editor
    navigator233
        14
    navigator233  
       Mar 18, 2024
    @chinazz 我也有类似需求 请问找到了好的工具了吗?
    chinazz
        15
    chinazz  
    OP
       Mar 18, 2024
    @navigator233 很久之前的需求了,后来记得是用 cookiecutter 模板工具实现的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1092 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 18:28 · PVG 02:28 · LAX 11:28 · JFK 14:28
    ♥ Do have faith in what you're doing.