I'm trying to find the "best practice" to return a JSON formatted string from a view function.
Basically, I plan to loop through a set of data stored in contract state, build it all into a single JSON string, and return the JSON string for further processing with web3.js. The format would be: "{'address': ['dataTiedToAddress','balance'], 'address2': ['dataTiedToAddress2','balance'], ...}"
I've found a couple question/answers on SO that relate to converting bytes values and addresses to strings (such as here: How to convert an address to bytes in Solidity?), but using the separate conversion functions in addition to string building seems a bit messy. I wasn't sure if there was a better way to do what I'm trying to achieve.
The following are the data types:
address
: address
dataTiedToAddress
: bytes
balance
: uint256
I'm trying to optimize as much as possible; however, since this is a view function only called by an administrative account in a back end process, a larger gas amount/longer processing is not a huge issue. In fact, I anticipate it will take a while due to the size of the data set.