api - Complex JSON data structure best practice -


i know of json data structure simpler , more convenient rest api consumers.

suppose, have post method, require complex data structure in request body. of structures more preferable? equavalent.

1.

{     searchpropertiesfilter: [         { key: 'key1', values: ['value1', 'value2'] },         { key: 'key1', values: ['value3', 'value4'] },         { key: 'key2', values: ['value5'] }     ],     resultpropertiescount: [         { key: 'key1', count: 100},         { key: 'key2', count: 500},     ] } 

2.

{     searchpropertiesfilter: {         'key1': [['value1', 'value2'], ['value3', 'value4']],         'key2': [['value5']]     }     resultpropertiescount: {         'key1': 100,         'key2': 500     } } 

on 1 hand, first example may simpler consumer. on other hand, second example shorter , don't contain property names.

by definition

json built on 2 structures:

a collection of name/value pairs. in various languages, realized object, record, struct, dictionary, hash table, keyed list, or associative array. ordered list of values. in languages, realized array, vector, list, or sequence.

so json key-value pair system, what’s point of redundancy of having pairs type key , value key when key:val do?

go version 2


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -