remove field from response output in python
up vote
1
down vote
favorite
Can any suggest how to remove field EventTime from below output in python3 using boto3 .
'Events': [{
'EventId': '4a9f4c8e-3394-41df-xxxx-7e725b7c728e',
'EventName': 'ConsoleLogin',
'ReadOnly': 'false',
'EventTime': datetime.datetime(2018, 11, 5, 9, 49, 19, tzinfo = tzlocal()),
'EventSource': 'signin.amazonaws.com',
'Username': 'tests.sde',
'Resources': ,
'CloudTrailEvent': '{"eventVersion":"1.05","userIdentity":
python-3.x boto3
add a comment |
up vote
1
down vote
favorite
Can any suggest how to remove field EventTime from below output in python3 using boto3 .
'Events': [{
'EventId': '4a9f4c8e-3394-41df-xxxx-7e725b7c728e',
'EventName': 'ConsoleLogin',
'ReadOnly': 'false',
'EventTime': datetime.datetime(2018, 11, 5, 9, 49, 19, tzinfo = tzlocal()),
'EventSource': 'signin.amazonaws.com',
'Username': 'tests.sde',
'Resources': ,
'CloudTrailEvent': '{"eventVersion":"1.05","userIdentity":
python-3.x boto3
Why do you want to remove it? The nice thing about json and/or dictionaries is that you can just ignore the keys/values you don't care about. You rarely need to actively remove them.
– Matt Messersmith
Nov 5 at 20:10
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Can any suggest how to remove field EventTime from below output in python3 using boto3 .
'Events': [{
'EventId': '4a9f4c8e-3394-41df-xxxx-7e725b7c728e',
'EventName': 'ConsoleLogin',
'ReadOnly': 'false',
'EventTime': datetime.datetime(2018, 11, 5, 9, 49, 19, tzinfo = tzlocal()),
'EventSource': 'signin.amazonaws.com',
'Username': 'tests.sde',
'Resources': ,
'CloudTrailEvent': '{"eventVersion":"1.05","userIdentity":
python-3.x boto3
Can any suggest how to remove field EventTime from below output in python3 using boto3 .
'Events': [{
'EventId': '4a9f4c8e-3394-41df-xxxx-7e725b7c728e',
'EventName': 'ConsoleLogin',
'ReadOnly': 'false',
'EventTime': datetime.datetime(2018, 11, 5, 9, 49, 19, tzinfo = tzlocal()),
'EventSource': 'signin.amazonaws.com',
'Username': 'tests.sde',
'Resources': ,
'CloudTrailEvent': '{"eventVersion":"1.05","userIdentity":
python-3.x boto3
python-3.x boto3
asked Nov 5 at 17:31
ravindert
61
61
Why do you want to remove it? The nice thing about json and/or dictionaries is that you can just ignore the keys/values you don't care about. You rarely need to actively remove them.
– Matt Messersmith
Nov 5 at 20:10
add a comment |
Why do you want to remove it? The nice thing about json and/or dictionaries is that you can just ignore the keys/values you don't care about. You rarely need to actively remove them.
– Matt Messersmith
Nov 5 at 20:10
Why do you want to remove it? The nice thing about json and/or dictionaries is that you can just ignore the keys/values you don't care about. You rarely need to actively remove them.
– Matt Messersmith
Nov 5 at 20:10
Why do you want to remove it? The nice thing about json and/or dictionaries is that you can just ignore the keys/values you don't care about. You rarely need to actively remove them.
– Matt Messersmith
Nov 5 at 20:10
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
The response syntax above is just a standard python dictionary. The one complication with the boto3
response syntax is the Events
key is really a dictionary wrapped in a list, but you can still use pop()
to remove the EventTime
key from that dictionary. In the example below I've named the output response
.
response['Events'][0].pop('EventTime', None)
print(response)
pop()
removes keys in-place so after you run the code and look at response
the EventTime
key will be removed.
add a comment |
up vote
0
down vote
This is a simple python element deletion from a dictionary. In your case you have a list of dictionaries. If you want to delete EventTime
in all the dictionaries that are in the 'Events':[{}]
. you can use the below code:
for event in response['Events']:
try:
del event['EventTime']
except KeyError:
print("Key 'EventTime' is not found")
The above code will delete the 'EventTime' and throws an error if it doesn't find any element with key EventTime
. In your case, I guess all the dictionaries will have it.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The response syntax above is just a standard python dictionary. The one complication with the boto3
response syntax is the Events
key is really a dictionary wrapped in a list, but you can still use pop()
to remove the EventTime
key from that dictionary. In the example below I've named the output response
.
response['Events'][0].pop('EventTime', None)
print(response)
pop()
removes keys in-place so after you run the code and look at response
the EventTime
key will be removed.
add a comment |
up vote
0
down vote
The response syntax above is just a standard python dictionary. The one complication with the boto3
response syntax is the Events
key is really a dictionary wrapped in a list, but you can still use pop()
to remove the EventTime
key from that dictionary. In the example below I've named the output response
.
response['Events'][0].pop('EventTime', None)
print(response)
pop()
removes keys in-place so after you run the code and look at response
the EventTime
key will be removed.
add a comment |
up vote
0
down vote
up vote
0
down vote
The response syntax above is just a standard python dictionary. The one complication with the boto3
response syntax is the Events
key is really a dictionary wrapped in a list, but you can still use pop()
to remove the EventTime
key from that dictionary. In the example below I've named the output response
.
response['Events'][0].pop('EventTime', None)
print(response)
pop()
removes keys in-place so after you run the code and look at response
the EventTime
key will be removed.
The response syntax above is just a standard python dictionary. The one complication with the boto3
response syntax is the Events
key is really a dictionary wrapped in a list, but you can still use pop()
to remove the EventTime
key from that dictionary. In the example below I've named the output response
.
response['Events'][0].pop('EventTime', None)
print(response)
pop()
removes keys in-place so after you run the code and look at response
the EventTime
key will be removed.
answered Nov 5 at 20:09
vealkind
1,156810
1,156810
add a comment |
add a comment |
up vote
0
down vote
This is a simple python element deletion from a dictionary. In your case you have a list of dictionaries. If you want to delete EventTime
in all the dictionaries that are in the 'Events':[{}]
. you can use the below code:
for event in response['Events']:
try:
del event['EventTime']
except KeyError:
print("Key 'EventTime' is not found")
The above code will delete the 'EventTime' and throws an error if it doesn't find any element with key EventTime
. In your case, I guess all the dictionaries will have it.
add a comment |
up vote
0
down vote
This is a simple python element deletion from a dictionary. In your case you have a list of dictionaries. If you want to delete EventTime
in all the dictionaries that are in the 'Events':[{}]
. you can use the below code:
for event in response['Events']:
try:
del event['EventTime']
except KeyError:
print("Key 'EventTime' is not found")
The above code will delete the 'EventTime' and throws an error if it doesn't find any element with key EventTime
. In your case, I guess all the dictionaries will have it.
add a comment |
up vote
0
down vote
up vote
0
down vote
This is a simple python element deletion from a dictionary. In your case you have a list of dictionaries. If you want to delete EventTime
in all the dictionaries that are in the 'Events':[{}]
. you can use the below code:
for event in response['Events']:
try:
del event['EventTime']
except KeyError:
print("Key 'EventTime' is not found")
The above code will delete the 'EventTime' and throws an error if it doesn't find any element with key EventTime
. In your case, I guess all the dictionaries will have it.
This is a simple python element deletion from a dictionary. In your case you have a list of dictionaries. If you want to delete EventTime
in all the dictionaries that are in the 'Events':[{}]
. you can use the below code:
for event in response['Events']:
try:
del event['EventTime']
except KeyError:
print("Key 'EventTime' is not found")
The above code will delete the 'EventTime' and throws an error if it doesn't find any element with key EventTime
. In your case, I guess all the dictionaries will have it.
answered Nov 8 at 19:12
user2534033
116
116
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53159356%2fremove-field-from-response-output-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Why do you want to remove it? The nice thing about json and/or dictionaries is that you can just ignore the keys/values you don't care about. You rarely need to actively remove them.
– Matt Messersmith
Nov 5 at 20:10