you can filter using the following:

a = list(filter(lambda x: x['name'] == 'IE_Traitement_0A', data['completedapps']))

a will contain a list of all dict that match your filter and then you can sort the the list for the latest one -- using whatever key to sort it by

sorted_a = sorted(a, key=lambda k: k['starttime'])

if you want only one then select the first element of sorted_a assuming it's not empty.

EDIT: use min instead of sorted thanks for the tip @VPfB

min_a = min(a, key=lambda k: k['starttime'])
Answer from gyx-hh on Stack Overflow
Top answer
1 of 3
2

you can filter using the following:

a = list(filter(lambda x: x['name'] == 'IE_Traitement_0A', data['completedapps']))

a will contain a list of all dict that match your filter and then you can sort the the list for the latest one -- using whatever key to sort it by

sorted_a = sorted(a, key=lambda k: k['starttime'])

if you want only one then select the first element of sorted_a assuming it's not empty.

EDIT: use min instead of sorted thanks for the tip @VPfB

min_a = min(a, key=lambda k: k['starttime'])
2 of 3
0
req_json = """{"completedapps" : [ {
    "starttime" : 1520863179923,
    "id" : "app-20180312145939-0183",
    "name" : "IE_Traitement_3",
    "cores" : 1,
    "user" : "root",
    "memoryperslave" : 1024,
    "submitdate" : "Mon Mar 12 14:59:39 CET 2018",
    "state" : "FINISHED",
    "duration" : 212967
  }, {
    "starttime" : 1520863398147,
    "id" : "app-20180312150318-0186",
    "name" : "IE_Traitement_3",
    "cores" : 1,
    "user" : "root",
    "memoryperslave" : 1024,
    "submitdate" : "Mon Mar 12 15:03:18 CET 2018",
    "state" : "FINISHED",
    "duration" : 6321
  }, {
    "starttime" : 1520863387941,
    "id" : "app-20180312150307-0185",
    "name" : "IE_Traitement_0A",
    "cores" : 1,
    "user" : "root",
    "memoryperslave" : 1024,
    "submitdate" : "Mon Mar 12 15:03:07 CET 2018",
    "state" : "FINISHED",
    "duration" : 149536
  } ]}"""

import json
data = json.loads(req_json)

print(sorted(data['completedapps'], key=lambda x: x['starttime'])[0]['id'])

out:

app-20180312145939-0183

Explanation: first get list of dict and sort then by timestamp.

Discussions

Python Json. Getting only the last element in the json array - Stack Overflow
I just started trying out python, and right now i am in a little bit of a dilemma. I am trying to print from a json documents, and i am only getting the last element in the array. [{ "FullMea... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - How do I get the last element of a json list? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives ยท Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
๐ŸŒ stackoverflow.com
July 15, 2021
json - How to get the last value from the list using python? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives ยท Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
๐ŸŒ stackoverflow.com
Get last item in JSON array with Python - Stack Overflow
I'm trying to grab the last item in a json array and haven't been able to come across any documentation that shows how to do this. {'numbers': [1, 2, 3]} how do I just get 3? ANSWERED: import json More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ reading the last element in a json file
r/learnpython on Reddit: Reading the last element in a json file
March 30, 2019 -

I have a json file that looks like this: https://gist.github.com/SirDarknight/95cf48d46c17059a5f42a38ec70c7fa5

What's the best way to get the last object's "Title" key? (In this case: Mercy Black (2019) )

Edit: I'm thinking about wrapping the whole thing in a list and then loading the list

๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 68394053 โ€บ how-do-i-get-the-last-element-of-a-json-list
python - How do I get the last element of a json list? - Stack Overflow
July 15, 2021 - How do I get the last element of a list? [closed] (20 answers) Closed 4 years ago. Here I'm trying to get the last m2id to print it into console. [{ "m2id":"865199733949071370", "author":{ "id":"862323352869797948" } }, { "m2id":"865199658103078925", "author":{ "id":"751742911682445312" } }] And here's the code I wrote for it. (r.json being the json above): data = r.json() for id in data: id3 = id["id"][-1] print(id3) Running the code gave me the last number of the first m2id, Which is not what I want.
๐ŸŒ
CoenRaets
jsonviewer.ai โ€บ python-get-last-element-in-list5-methods-with-code-examples
Python Get Last Element in List[5 Methods with Code Examples] - JSON Viewer
July 29, 2023 - Additionally, Python supports negative indexing, where -1 refers to the last element, -2 to the second last, and so forth. Positive indexing allows you to access elements from the start of the list, with starting index as 0.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 49505335 โ€บ how-to-get-the-last-value-from-the-list-using-python
json - How to get the last value from the list using python? - Stack Overflow
data = ['reply': '{"osc":{"version":"1.0"}}'] data1 = ['reply':'{"device":{"network":{"ipv4_dante":{"auto":"1.0"}}}}'] I need to get only the "1.0" value from data and data1 using python 3.6. How ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 77223566 โ€บ get-last-item-in-json-array-with-python
Get last item in JSON array with Python - Stack Overflow
import json array = json.load(str({'numbers': [1, 2, 3]})) lastItem = array['numbers'][-1] # This is the format. ... semi-related in that it shows examples of numpy multi-dimensional array vs python list access stackoverflow.com/questions/1...
Find elsewhere
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 63501465 โ€บ only-returns-the-last-element-of-the-list
python - Only returns the last element of the list? - Stack Overflow
August 20, 2020 - Copyimport json print(len(test_json)) # Using simple for loop for index in range(len(test_json)): shapes = test_json[index][u'shapes'] print(shapes) But this returns only the points from the last element of the list. How do I get all the points from this list?
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 65447666 โ€บ get-the-last-element-in-a-large-json-file-using-python
Get the Last Element in A Large JSON file using Python - Stack Overflow
import ijson with open('customerAccounts.json', 'rb') as file: for key, value in ijson.kvitems(file, ''): pass print(key, value) key and value are here the last values from the iteration process. There are other ways to get the latest value from an iteration that might be faster (e.g., using a deque of size 1), but this should do.
๐ŸŒ
Microsoft Power Platform Community
powerusers.microsoft.com โ€บ t5 โ€บ Building-Flows โ€บ Parsing-JSON-get-the-last-array โ€บ td-p โ€บ 1270092
Forums | Microsoft Power Platform Community
September 14, 2021 - Quickly search for answers, join discussions, post questions, and work smarter in your business applications by joining the Microsoft Dynamics 365 Community.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-how-to-get-the-last-element-of-list
Get the Last Element of List in Python - GeeksforGeeks
May 10, 2025 - The simplest and most efficient method uses negative indexing with a[-1]. In Python, we can use -1 as an index to access the last element directly. ... We can also find the last element by using len() function.
๐ŸŒ
SitePoint
sitepoint.com โ€บ javascript
How can I access last object in JSON array - JavaScript
February 2, 2015 - I have an object in localstorage and would like to match the last element that I have added when I called $(โ€˜formโ€™).serializeArray(); I am trying to match the text from a dropdown that is populated with the keys from loโ€ฆ
๐ŸŒ
PythonHow
pythonhow.com โ€บ how โ€บ get-the-last-element-of-a-list
Here is how to get the last element of a list in Python
New: Practice Python, JavaScript & SQL with AI feedback โ€” Try ActiveSkill free โ†’ ร— ... To get the last element of a list in Python, you can use the index -1.You can also use the pop() method to remove and return the last element of a list. This method removes the element from the list, ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python get the last element of a list
Python Get the Last Element of a List - Spark By {Examples}
May 31, 2024 - Have you ever needed to get the last element of a list in Python, but weren't sure of the best way to do it? There are several different methods you can
๐ŸŒ
Gatling
community.gatling.io โ€บ gatling (open-source)
Get last element of JSON tab of objects response - Gatling (Open-Source) - Gatling
June 28, 2023 - I have a project where I need to get the last object of a JSON list that is returned in JSON but I canโ€™t get any idea of how to from a .check My builder: ChainBuilder getAllOrders = exec(http("Orders: /api/orders") .get("/api/orders") .header("Authorization", "Bearer ${BearerToken}") .check(status().is(200)) .check(jsonPath("$..id").saveAs("OrderIds"))); The response of the get is "[ { "id": 3, "order_number": "{ord_nb}", "dat...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-get-last-element-in-list-how-to-select-the-last-item
Python Get Last Element in List โ€“ How to Select the Last Item
March 15, 2022 - Just like we established in the last section, each item in a list has an index number which starts at zero. In Python, we can also use negative values for these indexes. While the positive indexes start from 0 (which denotes the position of the first element), negative indexes start from -1, and this denotes the position of the last element.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ last element in list python
Program to Get the Last Element in List in Python - Scaler Topics
May 18, 2023 - Using negative indexing is a very efficient solution to get the last element from the list, even if the size of the list is large. The list[-n] gives the nth-to-last element of the list. In Python, the list class provides a method pop().
๐ŸŒ
EyeHunts
tutorial.eyehunts.com โ€บ home โ€บ get last element of list python
Get last element of list Python - Tutorial - EyeHunts
December 26, 2023 - A simple example code gets the last element. list1 = [1, 2, 3, 4, 5] ele = list1.pop() print(ele) print("Updated list: " + str(list1)) # another way a_list = ['zero', 'one', 'two', 'three'] print(a_list[-1]) print(a_list) ... You can do li[-n] to get the nth element starting from the end, it is just accessed by the index and it is faster than li[len(li) โ€“ 1]...