How to fetch particalur key's value of json data in streams

+1 vote
The data is in the following format in my stream:

"json" : {
                "InvoiceNo" : "INV101",
                "orderNo" : "ORD101",
                "Date" : "22/1/2018",
                "Status" : "Approved",
                "File" : "53616c7465645f5fe2da369fc03d47e28d1dff52cb61b830ed132c4cd1fefa26350e4aaa1f78aecb1a092e6a1d4faef0"

I want to fetch only the file's key value so that i can decrypt it which is in hex.Please advice.
asked Jul 27 by Raghavendra

2 Answers

0 votes

At the moment, you would have to do this within your application, i.e. extract the File entity from the full JSON which is passed back by MultiChain.

answered Jul 30 by MultiChain
+1 vote
In python (2.7**) on a terminal using RHEL7, I wrote a python function that grabbed the data from a JSON output from a Multichain, but you can use it to grab any piece of the above.

$ python

>>> import subprocess

>>> import json


>>def grabData(key,chainName,streamName):

...        data=[ ]

...        jray=subprocess.check_output(['multichain-cli',str('{}'.format(chainName)),'liststreamkeyitems',str('{}'.format(streamName)),str('{}'.format(key))])

...        print jray

...        djray=json.loads(str(jray))

...        for item in range(0, len(djray)):

...                data.append(djray[item]['data'])

...        return data


You should be able to fiddle with it to suit your needs (i.e.; change 'data' to 'file'), etc. Hope this helps :)
answered 4 days ago by M.Green