The solution when an empty object is returned in go's json.Marshal

When an empty object enters

func A() string {
	type ResponseData struct {
        //Not published because it starts with a lowercase letter
		name  string
		value int64
	}
	var rd []ResponseData
    rd = append(rd,ResponseData{
        name:"aaa",
        value:1
   })
	resRaw, _ := json.Marshal(rd)
	resultJSON := string(resRaw)
	return resultJSON
}

The field of ResponseData is not exposed. If you do this, [{}] ← like this will be included in the resultJSON.

OK guy

func A() string {
	type ResponseData struct {
        //It is published because the beginning is uppercase
		Name  string
		Value int64
	}
	var rd []ResponseData
    rd = append(rd,ResponseData{
        Name:"aaa",
        Value:1
   })
	resRaw, _ := json.Marshal(rd)
	resultJSON := string(resRaw)
	return resultJSON
}

By doing this, the field of ResponseData is exported, and as a result, the resultJSON will be filled with the value properly.

Recommended Posts

The solution when an empty object is returned in go's json.Marshal
When the selected object in bpy.context.selected_objects is not returned
Determine if an attribute is defined in the object
When the target is Ubuntu 16.04 in Ansible
[Solution] When inserting "0001" into the column of string in sqlite3, it is entered as "1".
Embedding in datetime when only the time is known
When reading an image with SimpleITK, there is a problem if there is Japanese in the path
I got an error when I tried to process luigi in parallel on windows, but the solution
Solution to the problem that the display is corrupted when the .exe command is included in the while loop in wsl2
How to know the internal structure of an object in Python
Check if the configuration file is read in an easy-to-understand manner
Python-docx The icon is strange when saved. → Solution (changed to Python-docx → pywin32)
I got an AttributeError when mocking the open method in python
[Linux] When the screen is cut off when installing CentOS in VirtualBox
[Golang] "package exec is not in GOROOT" when executing the test
Animate what happens in frequency space when the Nyquist frequency is exceeded
What to do when the value type is ambiguous in Python?
Solution when an error occurs when hiding the console screen with PyInstaller
[Question] In sk-learn random forest regression, an error occurs when the number of parallels is set to -1.
Get the attributes of an object
Python in is also an operator
When the node disappears in rqt_graph
What to do when the result downloaded via scrapy is in English
Python Note: When you want to know the attributes of an object
[Python] What to do when an error related to SSL authentication is returned
When issuing an INSERT statement in Python, no such column is displayed
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment