Search code examples
hyperledger-fabrichyperledgerhyperledger-composer

Invalid JSON data error in composer rest server


I am new to hyperledger. I am getting an error in composer rest server when I am making a post request. I am putting this in the request

{
  "$class": "org.example.biznet.SampleAsset",
  "assetId": "string",
  "owner": {},
  "value": "string"
}

and my cto file is namespace org.example.biznet

participant SampleParticipant identified by participantId {
  o String participantId
  o String firstName
  o String lastName
}

asset SampleAsset identified by assetId {
  o String assetId
  --> SampleParticipant owner
  o String value
}

transaction SampleTransaction {
  --> SampleAsset asset
  o String newValue
}

event SampleEvent {
  --> SampleAsset asset
  o String oldValue
  o String newValue
}

Solution

  • It looks like you are using the example JSON, but unfortunately there is an error with it.

    The owner property you have in the SampleAsset is a relationship, but it just needs to be represented as a string. In the post request you can just specify the ID of an owner e.g. "owner" : "7465", or you can specify the whole relationship string "owner" : "resource:org.example.biznet.SampleParticipant#7465",

    Note: that whatever you put in the owner field, the relationship will NOT be checked or resolved by Composer.