问题描述
我正在开发一个安全服务,该服务将返回权限列表,并且我正在尝试估计json响应对象的大小.这是一段示例数据:
I'm working on a security service that will return a list of permissions and I'm trying to estimate the size of the json response object. Here's a piece of sample data:
ID = 123VariableName = CanAccessSomeContent
ID=123VariableName=CanAccessSomeContent
我正在寻找一种简单的方法来估计1500行时json响应对象的大小.是否可以使用在线估算工具或其他一些技术轻松获得粗略的估算值?
I'm looking for an easy way to estimate what size of the json response object will be with 1500 rows. Is there an online estimation tool or some other technique I can use to easily get a rough size estimate?
推荐答案
使用Python,您可以通过创建字典来估计大小,也可以只制作一个...
Using Python you can estimate the size by creating the dictionary or just make one...
import json
import os
import sys
dict = {}
for a in range(0, 1500):
dict[a] = {'VariableName': 'CanAccessSomeContent'}
output = json.dumps(dict, indent = 4)
print ("Estimated size: " + str(sys.getsizeof(output) / 1024) + "KB")
with open( "test.json", 'wb') as outfile:
outfile.write(output)
print ("Actual size: " + str(os.path.getsize('test.json') / 1024) + "KB")
输出:
Estimated size: 100KB
Actual size: 99KB
这篇关于有没有一种简单的方法来估算json对象的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!