Ask Your Question
4

What is the method for eliminating additional space in Lambda's JSON output?

asked 2022-10-22 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-04-15 07:00:00 +0000

qstack gravatar image

One way to eliminate additional space in Lambda's JSON output is to use the json.dumps() method with the separators parameter. This parameter should be set to a tuple of two values: (',',':'). This will remove all whitespace characters from the output and replace the default separators with a comma and a colon. Here's an example:

import json

def lambda_handler(event, context):
    data = {"name": "John", "age": 30, "city": "New York"}
    json_data = json.dumps(data, separators=(',', ':'))
    print(json_data)

This code will output the following JSON string:

{"name":"John","age":30,"city":"New York"}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-10-22 11:00:00 +0000

Seen: 17 times

Last updated: Apr 15 '21