getJSON drops 80% of content

I’m trying to parse JSON contents (through a shortcode) and getting really weird results with 80% of the content just dropped.

I’ve simplified my code down to bare bones for debugging and now my JSON looks like that:

{
	  "rows": [
		{
			 "nothing" : "first",
			 "nothing" : "second",
			 "nothing" : "third",
			 "alert" : "fourth",
			 "nothing" : "fifth",
			 "nothing" : "sixth",
			 "alert" : "seventh",
			 "nothing" : "ninth",
			 "nothing" : "tenth"
		}
	  ]
}

I parse it through a shortcode like that:

{{ $file := .Get 0 }}
{{ $datasource := getJSON $file }}
{{ $datasource }}

And the result which I am NOT expecting is this:

map[rows:[map[alert:seventh nothing:tenth]]]

Only two key-value pairs are present.
What could be the reason? Where to approach the problem?

I’ve cleaned cache with hugo mod clean --all.

umm… the keys need to be unique? That applies to any table format.

1 Like

You can use resources.GetRemote to preserve the original string, but you will lose info as soon as you turn it into a data object.

Check out any online data format converter tool like Data Format Converter

Try to parse your snippet to YAML or anything and you see see this error:

Yeah, that explains, thanks. (It’s a really late hour here… :sweat_smile: )

1 Like