Python Forum
Aggregation json by nested elements
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Aggregation json by nested elements
#1
I have the following structure:
Output:
[ { "Name": "a-1", "Tags": [ { "Value": "a", "Key": "Type" } ], "CreationDate": "2018-02-25T17:33:19.000Z" }, { "Name": "a-2", "Tags": [ { "Value": "a", "Key": "Type" } ], "CreationDate": "2018-02-26T17:33:19.000Z" }, { "Name": "b-1", "Tags": [ { "Value": "b", "Key": "Type" } ], "CreationDate": "2018-01-21T17:33:19.000Z" }, { "Name": "b-2", "Tags": [ { "Value": "b", "Key": "Type" } ], "CreationDate": "2018-01-22T17:33:19.000Z" }, { "Name": "c-1", "Tags": [ { "Value": "c", "Key": "Type" } ], "CreationDate": "2018-08-29T17:33:19.000Z" } ]
I want group the json elements by Value and to print out the oldest Name of each Value when there are more than one member in the group (This should be configurable. For example: The x oldest items when there are more than y members in the group). In this case there are two a, two b and one c, So the expected result will be:
Output:
a-1 b-1
Any idea how to do that in Python?
Reply
#2
if you extract as dictionary, you can use:
see: https://www.saltycrane.com/blog/2007/09/...y-by-keys/
section: How to sort a dict by keys (Python older than 2.4):

Or to do as json: https://stackoverflow.com/questions/2692...n-by-value
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Parse Nested JSON String in Python mmm07 4 1,509 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Read nested data from JSON - Getting an error marlonbown 5 1,351 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Convert nested sample json api data into csv in python shantanu97 3 2,793 May-21-2022, 01:30 PM
Last Post: deanhystad
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,095 May-17-2022, 11:38 AM
Last Post: Larz60+
  Convert python dataframe to nested json kat417 1 6,308 Mar-18-2022, 09:14 PM
Last Post: kat417
  Problem with nested JSON Kalet 7 2,779 Dec-09-2021, 11:13 PM
Last Post: Gribouillis
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,911 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  Looping through nested elements and updating the original list Alex_James 3 2,111 Aug-19-2021, 12:05 PM
Last Post: Alex_James
  Sorting Elements via parameters pointing to those elements. rpalmer 3 2,579 Feb-10-2021, 04:53 PM
Last Post: rpalmer
  JSON response from REST service get nested value nl2ttl 2 2,515 Nov-30-2020, 09:34 PM
Last Post: nl2ttl

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020