Skip to content

iterating through objects as key value pairs (cf. pythons .items()) #543

@lukasheinrich

Description

@lukasheinrich

sometimes it's useful to process objects by iterating through the key value pairs

python has

obj = {"a": 1, "b": 2}
{k:v*2 for k,v in obj.items()}

jq has

echo '{"a": 1, "b": 2}'|jq '[to_entries[]|{key: .key, value: (.value * 2)}]|from_entries'

is there something similar in jsonnet? it seems like the list and object comprehensions could return (k,v) tuples if the right hand side is an object

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions