Send JSON to Starlark as string?

So, I am able to pull in JSON from an API within Starlark code running from pixlet using http.get(URL), however, if I try to send a JSON string in as a parameter, for example from BASH as:

pixlet render ./stars/nearest-ac.star nearestac="$RESULT"

The string is usable in the starlark code, however if I try to query it as JSON, I get the error:

Error: string has no .json field or method

I’ve tried json.enconde() and json.decode() to no avail.

Thanks,
Dan

Have you tried referencing the structure from json.decode(nearestac) as you would the structure from the http.get(…).json()?

Maybe if you include some kind of code snippet, it might be easier to answer.

OK, so here’s what I found, and the solution that will work. For some reason, I need to reference the string that comes in without the .json() , it’s treated like a dict and seems to work. Each method below results in identical output:

nearestac = config.get("nearestac")
nearestac = json.decode(nearestac)

nearestac2 = http.get("https://re-api.adsbexchange.com/re-api/?closest=33.xx,-111.xxx,30", headers={"re-api-key": "xxx-yyy-xx-zzxxxx-xxx"})

print(nearestac2.json()['aircraft'][0]['hex'])
print(nearestac2.json()['aircraft'][0]['flight'])

print(nearestac['aircraft'][0]['hex'])
print(nearestac['aircraft'][0]['flight'])