0

I am new to aws Lambda, I am struggling enough to find the solution dont know what to do. I have lambda handler function. my code is designed in such a way it works with the last value only. if I pass the data inside the console like:

Data=[['1700','340','2040']]

and pass it to lambda function. it works fine. But when I use API to pass the data as API request in configure test event and print the data , it change the json structure.

json data in test event:

{
    "sum_net": 1700,
    "sum_tax": 340,
    "sum_gross": 2040
}

Handler function:

def handler(event,extract)

data= event.values()

return 

result change the json object order. values are not the same as the manually defined dictionary. is there any way to keep the structure same.problem appears when json object changes to python dict. it changes the order of keys and values
Thank you in advance.

Ch HaXam
  • 499
  • 3
  • 16

2 Answers2

1

Extracted the answer from JSON order mixed up :

You may not rely on the ordering of elements within a JSON object.

From the JSON specification at http://www.json.org/

An object is an unordered set of name/value pairs

As a consequence, lambda and any other JSON libraries are free to rearrange the order of the elements as they see fit.

Community
  • 1
  • 1
tremendows
  • 4,262
  • 3
  • 34
  • 51
  • is there anyway I can rearrange them later in my lambda function not for one value but for 1000 value, which approach can I use. – Ch HaXam Jan 04 '17 at 10:39
0

The only way to change what lambda returns is to change lambda. If it is not an open-source AWS library and not open-source, it may not be easy at all.

If you know which is the value that you want from the handler, "sum_gross" I assume, you can directly get this value with the dictionary.get("key") method:

def handler(event,extract)

    data = event.get("sum_gross");

return 

more info about python dictionaries: http://www.tutorialspoint.com/python/dictionary_get.htm

tremendows
  • 4,262
  • 3
  • 34
  • 51