News for hackers. Stuff that matters.
Re:jq 1.7 released by PurpleRamen on Thursday September 07, 2023 @08:01AM (#37417683)
Assuming <data> will be a key-value-object aka dict, it would be something like this:

    import json
    data = json.loads('<data>')
    bar = None
    if foo:=data.get('foo'):
        bar = foo[0].bar    
    print(bar)
    
If you can't be sure to get a dict, another type-check would be necessary. If you read from a file or file-like-object (like sys.stdin), json.load should be used.

There are no comments on this comment yet.