{"action":"created","issue":{"url":"https://api.github.com/repos/IBM-Blockchain/learn-chaincode/issues/12","repository_url":"https://api.github.com/repos/IBM-Blockchain/learn-chaincode","labels_url":"https://api.github.com/repos/IBM-Blockchain/learn-chaincode/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/IBM-Blockchain/learn-chaincode/issues/12/comments","events_url":"https://api.github.com/repos/IBM-Blockchain/learn-chaincode/issues/12/events","html_url":"https://github.com/IBM-Blockchain/learn-chaincode/issues/12","id":159513044,"number":12,"title":"saving json array to state","user":{"login":"learner4","id":18212481,"avatar_url":"https://avatars.githubusercontent.com/u/18212481?v=3","gravatar_id":"","url":"https://api.github.com/users/learner4","html_url":"https://github.com/learner4","followers_url":"https://api.github.com/users/learner4/followers","following_url":"https://api.github.com/users/learner4/following{/other_user}","gists_url":"https://api.github.com/users/learner4/gists{/gist_id}","starred_url":"https://api.github.com/users/learner4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/learner4/subscriptions","organizations_url":"https://api.github.com/users/learner4/orgs","repos_url":"https://api.github.com/users/learner4/repos","events_url":"https://api.github.com/users/learner4/events{/privacy}","received_events_url":"https://api.github.com/users/learner4/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-06-09T21:31:23Z","updated_at":"2016-06-10T13:59:52Z","closed_at":null,"body":"I have tried storing and querying json array in the hyperledger - it always shows empty (but when I try to save and display it works fine.  is there any limitation to store json array?i checked to make sure there is no error on golang part. and no error posting to state as well - I get transaction message.  Any ideas what might be wrong, since state stored everything as byte array?\r\n\r\nstep1\r\ncreate struct array->marshal->bytearray->put state\r\nstep2\r\nread state -> empty array \"[]\"\r\n"},"comment":{"url":"https://api.github.com/repos/IBM-Blockchain/learn-chaincode/issues/comments/225189492","html_url":"https://github.com/IBM-Blockchain/learn-chaincode/issues/12#issuecomment-225189492","issue_url":"https://api.github.com/repos/IBM-Blockchain/learn-chaincode/issues/12","id":225189492,"user":{"login":"dshuffma-ibm","id":16085295,"avatar_url":"https://avatars.githubusercontent.com/u/16085295?v=3","gravatar_id":"","url":"https://api.github.com/users/dshuffma-ibm","html_url":"https://github.com/dshuffma-ibm","followers_url":"https://api.github.com/users/dshuffma-ibm/followers","following_url":"https://api.github.com/users/dshuffma-ibm/following{/other_user}","gists_url":"https://api.github.com/users/dshuffma-ibm/gists{/gist_id}","starred_url":"https://api.github.com/users/dshuffma-ibm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dshuffma-ibm/subscriptions","organizations_url":"https://api.github.com/users/dshuffma-ibm/orgs","repos_url":"https://api.github.com/users/dshuffma-ibm/repos","events_url":"https://api.github.com/users/dshuffma-ibm/events{/privacy}","received_events_url":"https://api.github.com/users/dshuffma-ibm/received_events","type":"User","site_admin":false},"created_at":"2016-06-10T13:59:52Z","updated_at":"2016-06-10T13:59:52Z","body":"Ok so if we keep looking at the marbles chaincode the trades book keeping is an array of structs.\r\n\r\n```\r\ntype AllTrades struct{\r\n\tOpenTrades []AnOpenTrade `json:\"open_trades\"`\r\n}\r\n```\r\n\r\n**[marbles chaincode](https://github.com/IBM-Blockchain/marbles-chaincode/blob/master/hyperledger/part2/part2_chaincode.go) line 407**\r\n```\r\n//get the open trade struct\r\ntradesAsBytes, err := stub.GetState(openTradesStr)\r\nif err != nil {\r\n\treturn nil, errors.New(\"Failed to get opentrades\")\r\n}\r\nvar trades AllTrades\r\njson.Unmarshal(tradesAsBytes, &trades)\t\t//un stringify it aka JSON.parse()\r\n\t\r\ntrades.OpenTrades = append(trades.OpenTrades, open);\t\t//append to open trades\r\nfmt.Println(\"! appended open to trades\")\r\njsonAsBytes, _ = json.Marshal(trades)\r\nerr = stub.PutState(openTradesStr, jsonAsBytes)\t//rewrite open orders\r\nif err != nil {\r\n\treturn nil, err\r\n}\r\n```\r\n\r\nIts not a tidy example but hopefully it helps. Its basically the same setup though.  If this doesn't match what you want, post your golang code."}}
{"actor":{"display_login":"dshuffma-ibm"}}