Closed Skeeve closed 8 months ago
Please take a look at the Options struct. You can configure the output in many different ways when it is passed to pretty.JSON()
or my preferred pretty.SEN()
.
I tried to but didn't get it.
fmt.Println(pretty.JSON(data2, oj.Options{KeyExact: true}))
is what I tried and still the keys were lowercase.
OTOH: "data.Name" is found when searching "name" which I think is an error.
Try fmt.Println(pretty.JSON(data2, &oj.Options{KeyExact: true}))
instead.
The searches are not case sensitive when search the field on a struct. The reason for that is that private struct names, those starting with a lowercase letter are not accessible so it doesn't make sense to search for a private field. You will probably find that in most cases camelBack names are used in JSON so it is reasonable to support that as the default behavior.
Thanks for your explanation.
Casing is correct now and the search-thing I understood.
Hi.
In my program I parse a custom struct. Everything works as expected, except when I pretty.JSON print my data.
Capitalization is lost for all type properties. On the other hand is it taken into account when searching for properties.
Please find below example program on the playground.
I have the (almost) same structure (taken from #111) once as a parsed JSON string (
data
) and once (data2
) as a struct.Please observe that Locate on the struct finds both
name
andName
when searching for "Name" but only 'name'. when searching for "name".Also only the parsed data is printed correctly while the struct data2 lost its capitalization.
Output: