json api到文档解析器

json-api-doc的Python项目详细描述


https://img.shields.io/pypi/v/json-api-doc.svghttps://img.shields.io/travis/noplay/json-api-doc.svgDocumentation StatusUpdates

这个库提供了在规范化json api之间进行转换的能力。 (http://jsonapi.org/)文档和 在代码中更容易操作。 也可用作命令行实用程序和Python3模块。

反序列化

对于这个json api文档:

{"data":[{"type":"articles","id":"1","attributes":{"title":"JSON API paints my bikeshed!","body":"The shortest article. Ever.","created":"2015-05-22T14:56:29.000Z","updated":"2015-05-22T14:56:28.000Z"},"relationships":{"author":{"data":{"id":"42","type":"people"}}}}],"included":[{"type":"people","id":"42","attributes":{"name":"John","age":80,"gender":"male"}}]}

简化版为:

[{"type":"articles","id":"1","title":"JSON API paints my bikeshed!","body":"The shortest article. Ever.","created":"2015-05-22T14:56:29.000Z","updated":"2015-05-22T14:56:28.000Z","author":{"type":"people","id":"42","name":"John","age":80,"gender":"male"}}]

序列化

将dict转换为json api规范文档对象的根 必须包含一个$type键,其值与 对象的资源类型。任何子指令或指令子数组 包含$type键将被视为包含的文档并序列化 因此。

[{"$type":"articles","id":"1","title":"JSON API paints my bikeshed!","body":"The shortest article. Ever.","created":"2015-05-22T14:56:29.000Z","updated":"2015-05-22T14:56:28.000Z","author":{"$type":"people","id":"42","name":"John","age":80,"gender":"male"}}]
{"data":[{"type":"articles","id":"1","attributes":{"title":"JSON API paints my bikeshed!","body":"The shortest article. Ever.","created":"2015-05-22T14:56:29.000Z","updated":"2015-05-22T14:56:28.000Z"},"relationships":{"author":{"data":{"id":"42","type":"people"}}}}],"included":[{"type":"people","id":"42","attributes":{"name":"John","age":80,"gender":"male"}}]}

用作python模块

importjson_api_docdocument={'data':{'type':'article','id':'1','attributes':{'name':'Article 1'}}}json_api_doc.deserialize(document)
importjson_api_docdocument={'$type':'article','id':'1','name':'Article 1'}json_api_doc.serialize(document)

用作cli

$ jsonapidoc document.json

贡献者

许可证

免费软件:apache软件许可证2.0

文件

提供完整的文档:https://json-api-doc.readthedocs.io

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java错误:无法解析方法   如何用相同的父标记和子标记在Java中解析XML?   日期使用Java中的时区偏移将本地时间转换为UTC   java如何在多进程、多线程环境中读取文件   WebView中的java弹出式对话框不在当前显示范围内,但在chrome浏览器中运行良好   只有2个参数的java递归二进制搜索方法   无法在java中调用函数   java JavaMail在Tomcat服务器上运行时停止工作   反射通过java程序生成、编译和运行java类   java Android:如何使ListView即使在应用程序关闭后仍保持禁用状态   在JAVA中识别匿名类实例   java渲染一个由三角形组成的立方体,在旋转时会产生奇怪的角度   函数式编程如何基于比较连续的列表元素将Java流减少为布尔值   java如何替换列表中的多个项目?   java Android如何获取随机sqlite数据?   java我已经将useSSL设置为false,但仍然收到警告   java使用动态变量生成jlabel   apachespark:java。lang.NoClassDefFoundError v2TableWithV1回退