Skip to content
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

How to create a JSON array #125

Open
carefree666 opened this issue Aug 27, 2022 · 3 comments
Open

How to create a JSON array #125

carefree666 opened this issue Aug 27, 2022 · 3 comments

Comments

@carefree666
Copy link

Desired results:
[{"id":"1","name":"test"}]

Results obtained now:
[{"id":"1","name":"test"},{"id":"1","name":"test"}]

code

jsonArray := gabs.New() jsonArray.Set("1", "id") jsonArray.Set("test", "name") jsonArray.ArrayAppend(jsonArray.Data())

No relevant information was found. Please share a solution

@buzzy
Copy link

buzzy commented Aug 30, 2022

mainObj := gabs.New()

subObj := gabs.New()
subObj.Set("1", "id")
subObj.Set("test", "name")

mainObj.Array()
mainObj.ArrayAppend(subObj.Data())

@carefree666
Copy link
Author

mainObj := gabs.New()

subObj := gabs.New() subObj.Set("1", "id") subObj.Set("test", "name")

mainObj.ArrayAppend(subObj.Data())

Use the method you said to execute the results :[{},{"id":"1","name":"test"}]
More {},Is there a way to remove it

@buzzy
Copy link

buzzy commented Sep 13, 2022

mainObj := gabs.New()

subObj := gabs.New() subObj.Set("1", "id") subObj.Set("test", "name")

mainObj.ArrayAppend(subObj.Data())

Use the method you said to execute the results :[{},{"id":"1","name":"test"}]
More {},Is there a way to remove it

I forgot the .Array()
Example has been updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants