Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bulk api result structure is different between xml and json #13117

Open
homewantad opened this issue Jun 30, 2018 · 2 comments
Open

bulk api result structure is different between xml and json #13117

homewantad opened this issue Jun 30, 2018 · 2 comments
Labels
RFC Indicates the issue is a request for comments where the author is looking for feedback.

Comments

@homewantad
Copy link

homewantad commented Jun 30, 2018

Hi there,

calling the bulk API provides different result structures between XML and json. I think the json format is actually wrong. Here is an example:

Calling: https://test.homewantad.com:943/?module=API&method=API.getBulkRequest, query segments for a VisitSummary, with period year for the last two years

urls[0]=method=VisitsSummary.get&idSite=1&period=year&date=last2&format=JSON&segment=pageU=^test.homewantad.com/ad/show/AWQh3OKzf2k4jhougDPr&urls[1]=method=VisitsSummary.get&idSite=1&period=year&date=last2&format=JSON&segment=pageUrl=^test.homewantad.com/ad/show/AWQx2EBr2vnhxw_A_uUe

The correct XML result structure is:

<result>
	<row>
		<row key="2017"></row>
		<row key="2018">...</row>
	</row>
	<row>
		<row key="2017"></row>
		<row key="2018">...</row>
	</row>
	<row></row>
</result>

The JSON structure does not match the xml structure (and has 3 problems, I think):

[{
    "2017": [],
    "2018": {
        "nb_visits": 1,
        "nb_actions": 45,
        "nb_visits_converted": 1,
        "bounce_count": 0,
        "sum_visit_length": 3396,
        "max_actions": 45,
        "bounce_rate": "0%",
        "nb_actions_per_visit": 45,
        "avg_time_on_site": 3396
    }
},
{
    "2017": [],
    "2018": {
        "nb_visits": 1,
        "nb_actions": 45,
        "nb_visits_converted": 1,
        "bounce_count": 0,
        "sum_visit_length": 3396,
        "max_actions": 45,
        "bounce_rate": "0%",
        "nb_actions_per_visit": 45,
        "avg_time_on_site": 3396
    }
}]

The following arguments are for an easy json to code mapping.

  • the whole json result structur is an array, it should be an json-object with an array inside like { [] }

  • the first json result-object has two fields. This is quitly difficult to map into a code representation. With an array instead, there are no problems:
    {[ { "2017" : { } ], [ { "2018" : { } ]} instead of { { "2017" : { } }, { "2018" : { } } }

  • the null representation for an object is {} or null, not [] in this context. [] is an empty array. An empty [] causes another problem for a dynamic mapping, when an object is expected and suddenly an array (empty) will be delivered.

With regards,
Dirk

@fdellwing
Copy link
Contributor

fdellwing commented Jun 30, 2018

Will just leave my thoughts about this:

The whole thing should be an JSON with an Array inside, not because it is really needed, but because thats what I exspect from an JSON API.

An empty value is not allowed to be [] if it will be an JSON with data.

So for me (coming from a JSONSimple context it would have to look like this:

{[
	{
		"2017": {},
		"2018": {...}
	},
	{
		"2017": {},
		"2018": {...}
	}
]}

So if you parse it, you will have an JSONObject (map) containing a JSONArray (list) containing JSONObjects (maps) containing JSONObjects (maps).

@homewantad
Copy link
Author

homewantad commented Jun 30, 2018

Almost that what I would expect:

JSONObject as "whole result" contains JSONObject (map) "result objects per bulk query" contains JSONObject (map) with "results objects per query, in my example the years" containing JSONObject (here Visit-class) with a field year and a object visit.

It's really a problem to map a field name "year" to a field of a class:

{ 
      "2017" : {},
     "2018" : {}
}

would be in Java:

class Visit {
       private 2017 visit;
       private 2018 visit;
}

I would expect

class Visit {
      private String year;
      private Visit visit;
}

and therefore a class Result with an Array of Visits as a field

private Visit[] visits.

When there are no results for a query, than [] is a zero result array and that's ok. When result of the query is only an object, than I would expect {} and not an empty array [].

Here the structure, that I would expect:

{[
	[ <---- here an array instead of a json object
		{     "year" : "2017", <--- that's correct, but as own object (one result object Visit for url[0])
                       "visit" : {}   
                },
		{      } <---- second result object for url[0]
	],
	[
		{         }, <---- first result object for url[1]
		{         } <----- second result object for url[1]
	],
        [] <----- no results for url[2] 
]}

@Findus23 Findus23 added the RFC Indicates the issue is a request for comments where the author is looking for feedback. label May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Indicates the issue is a request for comments where the author is looking for feedback.
Projects
None yet
Development

No branches or pull requests

4 participants