简体   繁体   English

使用jsonpickle从python中的json序列化中排除字段

[英]excluding fields from json serialization in python using jsonpickle

I am using jsonpickle to serialize an object to json. 我正在使用jsonpickle将对象序列化为json。 The object has certain fields that point to other objects. 该对象具有指向其他对象的某些字段。 I'd like to selectively not include those in the serialization, so that the resulting json file is essentially pure human-readable text without any funny representations of objects. 我想有选择地在序列化中包括那些,以便生成的json文件本质上是纯人类可读的文本,没有任何有趣的对象表示形式。 Is there a way to make jsonpickle ignore certain object fields when serialization? 有没有一种方法可以使jsonpickle在序列化时忽略某些对象字段? Or more generally, include only fields that are "primitive" or easily serializable fields, like dictionaries, ints, lists of dicts, etc. 或更笼统地说,仅包括“原始”或易于序列化的字段,例如字典,整数,字典列表等。

thanks. 谢谢。

I think what you might be looking for is the unpicklable argument (see this doc for details). 我认为您可能要寻找的是无法拾取的参数(有关详细信息,请参阅此文档 )。 In short, if this argument is set to False , jsonpickle will not output custom python classes to JSON. 简而言之,如果将此参数设置为False ,则jsonpickle不会将自定义python类输出为JSON。 It should only output JSON native types eg strings, ints, bools and lists. 它仅应输出JSON本机类型,例如字符串,整数,布尔值和列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM