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

Return a valid JSON String() output for network lists #226

Closed
wants to merge 1 commit into from

Conversation

moul
Copy link

@moul moul commented Jul 3, 2016

Hi, what do you think about JSON marshalling lists as you are already doing with standalone items ?

If you like the idea, I can continue on the other resource types


Before

fmt.Println(myList)
// output: [{"a": "hello", "c": 42} {"a": "world", "c": 1337}] -> invalid json

After

fmt.Println(myList)
// output: [{"a": "hello", "c": 42},{"a": "world", "c": 1337}] -> valid json

@QuentinPerez
Copy link

LGTM

@shirou
Copy link
Owner

shirou commented Jul 3, 2016

Sorry, could you tell me more detail about what is a problem?

    V := InterfaceStat{
        MTU:  1500,
        Name: "eth0",
        Addrs: []InterfaceAddr{
            {Addr: "1.2.3.4"}, {Addr: "5.6.7.8"},
        },
    }
        fmt.Println(V)

returns {"mtu":1500,"name":"eth0","hardwareaddr":"","flags":null,"addrs":[{"addr":"1.2.3.4"},{"addr":"5.6.7.8"}]} and it is valid.

@moul
Copy link
Author

moul commented Jul 4, 2016

Your example is correct, it works perfectly for standalone items, but JSON is invalid as soon as you print a list (space separator instead of comma)

@shirou
Copy link
Owner

shirou commented Jul 5, 2016

I got it. You want to use InterfaceStat.Addrs individually. Thank you for teach me.

If you make types for other items, I will appreciate and merge it.

@moul
Copy link
Author

moul commented Jul 5, 2016

Perfect :)

@shirou shirou mentioned this pull request Oct 25, 2020
14 tasks
@shirou
Copy link
Owner

shirou commented Nov 1, 2020

Sorry for the very long time wait. fixed by #938.

@shirou shirou closed this Nov 1, 2020
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

Successfully merging this pull request may close these issues.

3 participants