V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2019-12-03 15:19:12 +08:00 · 4019 次点击
    这是一个创建于 1578 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    15 条回复    2024-03-18 14:56:12 +08:00
    inorilzy
        1
    inorilzy  
       2019-12-03 15:26:02 +08:00
    自己写,想生成啥样生成啥样,也不是很难吧。
    danbai
        2
    danbai  
       2019-12-03 15:29:40 +08:00
    写个类 然后存入数据 转成 json
    Trim21
        3
    Trim21  
       2019-12-03 15:31:36 +08:00
    pydantic?
    Vegetable
        4
    Vegetable  
       2019-12-03 15:32:10 +08:00
    完全看不懂是要干什么...json 模板?json 还需要模板吗?那不就是写好了序列化方法的数据结构吗?实际上不就是类吗
    chinazz
        5
    chinazz  
    OP
       2019-12-03 15:39:01 +08:00
    大概就是 A 同学想自己定义一个代码或者 json 模板。我们这边代码逻辑不关注他们的模板长什么样子,向模板里边填入数据。
    danbai
        6
    danbai  
       2019-12-03 15:43:48 +08:00
    json 不知道数据格式怎么填数据 难道你要返回个 map 吗
    至少你得拿到 A 同学的 json 格式 然后根据格式生成或写个类 然后代码根据类字段填值返回 json
    ddzzhen
        7
    ddzzhen  
       2019-12-03 15:45:46 +08:00 via Android
    难道不是一个函数就搞定了?
    eGlhb2Jhb2Jhbw
        8
    eGlhb2Jhb2Jhbw  
       2019-12-03 15:46:13 +08:00
    neoblackcap
        9
    neoblackcap  
       2019-12-03 15:46:49 +08:00
    json 模板不行,json schema 可以
    chinazz
        10
    chinazz  
    OP
       2019-12-03 16:03:37 +08:00
    @eGlhb2Jhb2Jhbw 哇!就是这种。不过他们需要那种正反双向都支持的,不仅能加载成 json,还能从 json 加载出数据。
    holajamc
        11
    holajamc  
       2019-12-03 16:40:42 +08:00
    jinjia2?
    superrichman
        12
    superrichman  
       2019-12-03 20:27:07 +08:00
    用自带的 json 库再加 jinja2 就行. 读写都可以
    iamsk
        13
    iamsk  
       2019-12-03 20:40:36 +08:00
    搜一下 json editor,json schema editor
    navigator233
        14
    navigator233  
       11 天前
    @chinazz 我也有类似需求 请问找到了好的工具了吗?
    chinazz
        15
    chinazz  
    OP
       11 天前
    @navigator233 很久之前的需求了,后来记得是用 cookiecutter 模板工具实现的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5333 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 08:06 · PVG 16:06 · LAX 01:06 · JFK 04:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.