How can I parse JSON in solidity?
The idea is to have a function or similar which is able to parse JSON inside a Solidity contract.
With a simple JSON object (only key value strings, like {'A': 'a', 'B': 'b'}
) the solution should be able to transform it to a mapping(string => string).
Best Answer
I'll assume that you want to call an external source on which you can't have control and that you use the json() Oraclize datasource in order to get only the right part of the service json that is returned when you call it's URL as indicated in Oraclize Available Datasources documentation.
For now I think you have no way to make Oraclize return anything else than a string. That means that you have to get the returned Json as a string parameter of your oraclize
__callback
function.But then, as you ask, you need to parse the json to an array. This would be very costly even if you find a way to do it.
So the short answer would be that what you ask is not possible.
However, let me suggest the following, not totally satisfactory, workarounds. I know it's just workarounds that probably won't fit your needs but I think that what you want to do is not possible for now, so let's just try to go closest as possible from the goal.
Workarounds: