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, 2018 by Raghavendra
Hi Raghavendra, can you tell me how did you design your own JSON format for your stream in multichain ?

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, 2018 by MultiChain
Hi. i thought i'd ask the the OP, Mr.Raghavendra about this, but he may not be active on this forum so i'll ask you instead.

how did the OP make his own, custom JSON there ?
As far as i have seen, the data streams have a pretty fixed JSON format and the only fields we can alter are the "Key" and "Data".

can you kindly elaborate how we can make custom JSON formats like the one stated above ?

any help is most appreciated !
If you want to create you own json format for the data then you can simply pass the data in your json format.
But tweaking with the default json format of the API command is not possible for now.

Although you can make your own API method to do so if are familiar with the functions internal to the multichain code.
can you guide me a little on how to make our own API method ?

maybe a tutorial or a similar case with some code showing how one could go about making a custom API method ?
+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 Aug 13, 2018 by M.Green
...