Skip to content

Load Flattened Data into Container (With arrays) #143

@WTIGER001

Description

@WTIGER001

I have tried the following with flattened JSON data like

`
flattenedData := map[string]interface{}{
"foo.arr.0": "apple",
"foo.arr.1": "banana",
"oarr.0.id": "id1",
"oarr.1.id": "id2",
}

// Create a new gabs container
container := gabs.New()

// Iterate through the flattened data and set values in the container
for path, value := range flattenedData {
	container.SetP(value, path)
}

// Print the nested JSON as a string
fmt.Println(container.StringIndent("", "  "))

`

I get

{ "foo": { "arr": { "0": "apple", "1": "banana" } }, "oarr": { "0": { "id": "id1" }, "1": { "id": "id2" } } }

Instead of

{ "foo": { "arr": [ "apple", "banana"] "oarr": [ { "id": "id1" }, { "id": "id2" } ] }

Is there a known way on how I can load this flattened data back into the container? It is using my array indexes as map keys right now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions