1

I am looping through a WebService in Python which returns me partially data. I am calling the WebService until i receive an "End of Data" in the response.

The returned objects are always the same structure. They are only part of a large data which the WebService returns in chunks of 1000.

I am saving the returned JSON string in a data variable. How can i copy JSON array data_next to JSON array in variable `data' or merge both JSON files.

STORM
  • 4,005
  • 11
  • 49
  • 98
  • 2
    Possible duplicate of [How to merge two dictionaries in a single expression?](https://stackoverflow.com/questions/38987/how-to-merge-two-dictionaries-in-a-single-expression) – tripleee Oct 15 '18 at 11:38
  • 1
    You should post an example of the data you are receiving. – zipa Oct 15 '18 at 11:39
  • The answer will depend on the format of the data you're receiving. Send an example. – Sam Oct 15 '18 at 11:53

2 Answers2

0

Let say you receive something like resp1 = '{"data": [...]}' and store it in a dictionary d. Assuming you do that using json package as follows:

d = json.loads(resp1)

For the next batch of data, you should store it in a temporal dictionary td, extract the field "data_next" and append it into the original dictionary:

td = json.loads(respN)
d["data"].append(td["data_next"])
gustavovelascoh
  • 1,208
  • 1
  • 14
  • 28
0

Let us consider two list A =[{"a":"apple"},{"b":"banana"}] and list B = [{"c":"cat"}]

try below in python 3 to get merged array.

A.__add__(B)