diff --git a/chaincode/fabcar/go/fabcar.go b/chaincode/fabcar/go/fabcar.go index f1c526aefb..7a7c70bec3 100644 --- a/chaincode/fabcar/go/fabcar.go +++ b/chaincode/fabcar/go/fabcar.go @@ -152,18 +152,16 @@ func (s *SmartContract) queryAllCars(APIstub shim.ChaincodeStubInterface) pb.Res return shim.Error(err.Error()) } // Add a comma before array members, suppress it for the first array member - if bArrayMemberAlreadyWritten == true { + if bArrayMemberAlreadyWritten { buffer.WriteString(",") } - buffer.WriteString("{\"Key\":") - buffer.WriteString("\"") - buffer.WriteString(queryResponse.Key) - buffer.WriteString("\"") - - buffer.WriteString(", \"Record\":") - // Record is a JSON object, so we write as-is - buffer.WriteString(string(queryResponse.Value)) - buffer.WriteString("}") + + buffer.WriteString( + fmt.Sprintf( + `{"Key":"%s", "Record":%s}`, + queryResponse.Key, queryResponse.Value, + ), + ) bArrayMemberAlreadyWritten = true } buffer.WriteString("]") diff --git a/chaincode/fabcar/go/go.mod b/chaincode/fabcar/go/go.mod index 67c7c9c5c0..1dd1a8a7a1 100644 --- a/chaincode/fabcar/go/go.mod +++ b/chaincode/fabcar/go/go.mod @@ -8,5 +8,6 @@ require ( golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // indirect golang.org/x/text v0.3.2 // indirect + google.golang.org/appengine v1.4.0 // indirect google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect )