We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suppose I have a target: { 'a': 1, 'b': 2, 'c': [{ 'd': 3, 'e': 4 }] }
{ 'a': 1, 'b': 2, 'c': [{ 'd': 3, 'e': 4 }] }
how would I write a spec to produce the output: { 'my_output': { 'a_and_b': [1, 2], 'c': [{ 'new_d': 3, 'new_e': 4 }] } }
{ 'my_output': { 'a_and_b': [1, 2], 'c': [{ 'new_d': 3, 'new_e': 4 }] } }
the part I am hung up on, is how to take 'a' and 'b' and get them into an array...
spec = { 'my_output': { 'a_and_b': ['a', 'b'], 'c': ('c', [{'new_d': 'd', 'new_e': 'e'}]) } }
The text was updated successfully, but these errors were encountered:
you want the Fill spec:
Fill
>>> from glom import glom, Fill, T >>> target = {'a': 1, 'b': 2} >>> glom(target, Fill([T['a'], T['b']])) [1, 2]
Fill is for "data structure as a template" use cases like this.
in the full context:
>>> target = { 'a': 1, 'b': 2, 'c': [{ 'd': 3, 'e': 4 }] } >>> spec = {'my_output': {'a_and_b': Fill([T['a'], T['b']]), ... 'c': ('c', [{'new_d': 'd', 'new_e': 'e'}]) } } >>> glom(target, spec) {'my_output': {'a_and_b': [1, 2], 'c': [{'new_d': 3, 'new_e': 4}]}}
Sorry, something went wrong.
No branches or pull requests
Suppose I have a target:
{ 'a': 1, 'b': 2, 'c': [{ 'd': 3, 'e': 4 }] }
how would I write a spec to produce the output:
{ 'my_output': { 'a_and_b': [1, 2], 'c': [{ 'new_d': 3, 'new_e': 4 }] } }
the part I am hung up on, is how to take 'a' and 'b' and get them into an array...
spec = { 'my_output': { 'a_and_b': ['a', 'b'], 'c': ('c', [{'new_d': 'd', 'new_e': 'e'}]) } }
The text was updated successfully, but these errors were encountered: