github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/types/json_object.go (about)

     1  package types
     2  
     3  import "encoding/json"
     4  
     5  // JSONObject represents a JSON object. When not initialized it serializes to `{}`,
     6  // whereas a `map[string]interface{}` serializes to `null`.
     7  type JSONObject map[string]interface{}
     8  
     9  func (j JSONObject) MarshalJSON() ([]byte, error) {
    10  	switch len(j) {
    11  	case 0:
    12  		return []byte("{}"), nil
    13  	default:
    14  		return json.Marshal(map[string]interface{}(j))
    15  	}
    16  }