-
-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
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
Parse Json Array issue: Unable to unmarshal object #924
Comments
Hi @NicoHood - thanks for logging this!
$ gomplate -d 'cities=test.json?type=application/array+json' -d 'weather=https://wttr.in/?0' -H 'weather=User-Agent: curl' -f test.tmpl
1: Weather report: London
\ / Sunny
.-. 20 °C
― ( ) ― ↑ 15 km/h
`-’ 10 km
/ \ 0.4 mm
2: Weather report: Johannesburg
\ / Clear
.-. 11..13 °C
― ( ) ― ↓ 17 km/h
`-’ 10 km
/ \ 0.0 mm
3: Weather report: Windhoek
\ / Clear
.-. 14 °C
― ( ) ― ↑ 12 km/h
`-’ 10 km
/ \ 0.0 mm See https://docs.gomplate.ca/datasources/#mime-types for more details, and especially https://docs.gomplate.ca/datasources/#overriding-mime-types |
WTF, there is a special mime type for this!? That was new to me, thanks! Edit: Maybe add this to your post or readme? |
@NicoHood which post? which README? It's in the docs, as I linked. |
Oh, my fault. I was referring to this post: It might be useful to add this note there, as it looks like a common usecase to connect a rest api to such a template. I was not aware that there is a special json array mime type, I thought it is all the same. |
Wild - I didn't know anyone read those 😂
Not sure that really makes sense... I didn't use a JSON array file as a datasource in that article directly, and where I did mention using datasources, I linked straight to the docs, which is where you'd find the answer.
It's is a bit of a hack TBH... JSON suffers from being a bit too general sometimes, and YAML even more so. So it's tough to make the right call when parsing sometimes. However, I have thought in the past about maybe attempting to parse as an array if the file can't be parsed as an object. I'll re-open this and just add a workaround to make this simpler. |
Hi,
I am not sure if this is an issue or if I just did something obvious wrong. Maybe you can help and other will see the post if they run into the same issue.
test.json
test.tmpl
command:
It works if you use
city: [...]
in json and(ds "cities").city
inside the template. But my json root object is not dict, it is an array, because I request it via REST api (common usecase).Thanks :-)
The text was updated successfully, but these errors were encountered: