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
Copyimport 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/18272160/…
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 localStorage. I have managed this. I then check to see if I have a match ...
🌐
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
🌐
PythonHow
pythonhow.com › how › get-the-last-element-of-a-list
Here is how to get the last element of a list in Python
my_list = [1, 2, 3, 4] if len(my_list) > 0: last_element = my_list.pop() else: # handle the empty list case last_element = None # or some other default value ... Solve Python exercises and get instant AI feedback on your solutions. Try ActiveSkill for Free → ... Use the polars library Use Selenium to browse a page Load JSON data Build a GUI with FreeSimpleGUI Delete a directory Delete a file Create matplotlib graphs Rename a file Get today's date and convert to string Create a text file and write text on it Read a text file with Python Scrape a Wikipedia page Install dependencies Flush the o
🌐
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.
🌐
Cloudera Community
community.cloudera.com › t5 › Support-Questions › find-last-element-of-json-in-nifi › m-p › 322690
Solved: find last element of json in nifi - Cloudera Community - 322690
August 19, 2021 - One of the JSON values needs to find the string last element. how to get the particular value in attribute with the last element. { "TOT_NET_AMT" : "55.00", "H_OBJECT" : "File", "H_GROSS_AMNT" : " ... Much appreciate it in advance. ... { "TOT_NET_AMT" : "55.00", "H_OBJECT" : "File", "H_GROSS_AMNT" : ["55.00","58.00"], "TOT_TAX_AMT" : "9.55" } If the value of H gross amount is in List of String ["55.00","58.00"] instead of String "55.00,58.00" , then you can use Jolt transformation JSON NiFi processor to define jolt spec to convert into the required output.