Questions tagged [glom]

glom is a Python module for declaratively accessing and transforming data

Features

  • Path-based access for nested structures
  • Declarative data transformation using lightweight, Pythonic specifications
  • Readable, meaningful error messages
  • Built-in data exploration and debugging features
  • Command-line interface (CLI) available

Links

33 questions
1
vote
1 answer

Extract nodes from json based on user input preserveing a portion of the higher level object as well

need to extract object from the given json based on the node chain passed by user and neglect those which are not in user input, then create a new json object my master json is : { "menustructure": [ { "node":"Admin", …
vineet singh
  • 173
  • 2
  • 12
1
vote
1 answer

Parsing deeply nested dictionary with python & glom

I have a deeply nested data presented as dictionary with mix of lists & dicts (e.g. Dict -> List of dicts -> Dict -> List of dicts). I'd like to parse it's values with glom (hopefully to something pandas-dataframeable), but struggling with mixing…
Krank
  • 141
  • 1
  • 8
1
vote
0 answers

Transform a dictionary to a string with glom

I have the following variants of input data: show_version_ios_parsed = { "version": { "uptime": "7 weeks, 6 days, 3 hours, 37 minutes", } } and show_version_nxos_parsed = { "platform": { "kernel_uptime": {"days": 102,…
1
vote
1 answer

Flatten nested dictionary using glom

I have a nested default dict that looks like the following: source["China"]["Beijing"] = { "num_persons" : 1454324, "num_cars" : 134 } source["Greece"]["Athens"] = { "num_persons" : 2332, "num_cars" : 12 } How do I transform the…
Demeter P. Chen
  • 823
  • 1
  • 7
  • 16
1
vote
1 answer

Use glom to get Index while iterating over an list of dictionaries

from glom import glom, T from glom.core import Val target = [ {"firstname": 'boka', 'lastname':'raton'}, {"firstname": 'cape', 'lastname':'town'} ] spec = ([{ 'fname':'firstname', 'index': Val('0') }]) r = glom(target,…
Lone Ronin
  • 2,530
  • 1
  • 19
  • 31
1
vote
1 answer

Nested dictionary to pandas df concatenating rows

Given the following dict: j = { "source": "https://example.com", "timestamp": "2021-04-12T19:34:24Z", "durationInTicks": 1082400000, "duration": "PT1M48.24S", "combinedRecognizedPhrases": [ { "channel": 0, "lexical":…
Steven González
  • 227
  • 1
  • 12
1
vote
1 answer

Python glom with list of records group common unique client_ids together as key

I just discovered glom and the tutorial makes sense, but I can't figure out the right spec to use for chrome BrowserHistory.json entries to create a data structure grouped by client_id or if this is even the right use of glom. I think I can…
zephyr707
  • 173
  • 1
  • 8
1
vote
1 answer

Using glom, how can I concatenate optional strings?

I have a dict containing a name in two parts: target = { "givenName": "Elvis", "middleName": "Aron", } middleName is optional. I need to map to them one string, which is either givenName + ' ' + middleName if middleName is defined or just…
Dag Høidahl
  • 7,873
  • 8
  • 53
  • 66
1
vote
1 answer

Using Glom on a nested structure, how to I move top level dictionary fields into a list of dictionaries?

This is a question about the usage of Glom (https://github.com/mahmoud/glom/) I have a dictionary that includes a list of other dictionaries. {'date': '2020-01-01', 'location': 'A', 'items': [ {'name': 'A', 'id': 'A1'}, {'name': 'B',…
576i
  • 7,579
  • 12
  • 55
  • 92
1
vote
1 answer

Using the glom library with Python: Turning a list result into a dictionary with key generated by a Python function

I'm using the Python library glom to extract data from a dictionary that contains lists. This question is about unterstanding how glom works with user defined functions and how I can move data from lists into dictionaries within glom. As an example,…
576i
  • 7,579
  • 12
  • 55
  • 92
1
vote
1 answer

Glom spec for list of dictionaries inside a list of dictionaries

I am currently using glom to parse through a JSON API response, which returns, among other things, a list of dictionaries, with a list of dictionaries inside it. The problem I'm having is getting glom to access the correct dictionary entry. Example…
0
votes
1 answer

Extract nodes from json based on user input

I need to extract object from the given json based on the node chain passed by user and neglect those which are not in user input, then create a new json object my master json is : { "menustructure": [ { …
vineet singh
  • 173
  • 2
  • 12
0
votes
1 answer

Glom: spec that creates an array from a string

In Python, given a dict in input as follows: input = { 'foo': 'bar' } which glom spec should I use to transform it into an array with a single item? spec = ? glom(input, spec) # ['bar'] I can't find any reference for such a transformation in…
Federinik
  • 523
  • 4
  • 20
0
votes
1 answer

glom assign based on data

In the following code, I am trying to mask personal information based on data. I have two scenarioes. In scenario 1, I want to update when type = 'FirstName', update or assign valueString value to "Masked". In scenario 2, I want to update when…
subra
  • 35
  • 6
0
votes
2 answers

Parsing JSON with Glom

I am trying to parse a JSON object and am having a difficult time accessing a value in a way that I can then merge with another df. The path for the value is: QueryResponse.Purchase[0].Line[0].Amount This spec will give me the first…
Tom Woods
  • 19
  • 2