zhanbei / uzbei.com

Yu Zhanbei's Blog, technically and personally.

Home Page:https://uzbei.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compressed Structure of Array of Objects in JSON for API Design

zhanbei opened this issue · comments

Compressing an Array of Objects in JSON for API Design

For an array of objects in JSON, their keys can be compressed,
using a format like table to store their keys and values.

Like some general objects can be represented by the following JSON:

The average size reduced may be calculated and analyzed, to be considered with performance.

{
	"keys": ["id", "name", "description", "value"],
	"values": [
		[1, 2, 3, 4, 5, 6, 7, 8, 9],
		["A", "B", "C", "D", "E"],
		["Des", "", "Des", "", "Des"],
		[92, 43, 54, 639, 2894, 3891]
	]
}

Like a serial of values with timestamps may often be compressed as:

{
	"from": "2020-02-17", "to": "2020-03-02",
	"values": [92, 43, 54, 639, 2894, 3891, 4238, 34853, 3539]
}