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第三方库


热门话题
使用Scala对Java进行单元测试?   java无法将应用程序部署到Tomcat   java如何在IntelliJ IDEA中创建补丁?   java如何在安卓中编程设置列表视图高度   java如何使用charAt检查字符串是否以AZ或AZ开头?   java在SQL查询中使用非限制值   java函数在不同的Android版本中返回不同的datetime值   java方法应该在实现动作的类中,还是在实现的类中?   java从另一个线程的类访问线程类的公共静态arrayList   java是否像重新引发相同的异常?   java如何从localhost访问本地文件   javaurl。openStream非常慢   java数组越界和空指针异常   java我只是在某种程度上破坏了Netbeans,我不知道如何修复它   java是否可以延迟类的加载,而这些类可能在以后动态加载?   java断开外壳输出到文件   从blob服务回调时出现java Google应用程序引擎错误   java将SparseArray存储在JSON中并使用它   使用IText for Java进行pdf文本定位   java如何更改SearchView的样式?