Can you post an example of your JSON and what the output should look like?
If I understand you correctly, then the code below should help.
For now you can use something like
type Location struct {
Type string `json:"myOtherName"`
Coordinates [2]float64 `json:"DoesNotHaveToBeCoordinates"`
}
This will automatically get the field myOtherName into Type and
DoesNotHaveToBeCoordinates into Coordinates without you need to pre-process
anything.
Or in case the most outter is an object that contains an array of elements
that you need in the struct. You can do something like
type Location struct {
Type string `json:"myOtherName"`
Coordinates [2]float64 `json:"DoesNotHaveToBeCoordinates"`
}
type Container struct {
ListOfLoc []Location `json:"ListOfLocation"`
}
This will allow to to have separate Location slice and you could throw the
Container away afterward.
On Sunday, September 29, 2013 9:58:37 PM UTC+7, Tobias Contreras wrote:
Receiving a json string, I have no control over, has an element that is an
object or array of objects. How do I read the json to convert the element
from object to array of the single object so I can set the json to a strict.
Thought about regex replace or Marshall to interface then try to reset
element as array of interface then hopefully assert to struct . ( no idea
if any of that is possible yet, still new)
Thanks for any insight.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.