I get msg.data as JSON. How can I parse it in my contract to create variables in my contract with given values?


1 Answer 1


It would be less expensive to parse the JSON outside the EVM and send the extracted values as parameters to your contract, if that is at all feasible in your design.

  • My exact problem is like this: I need a function to take variable number of arguments. Eg. in one call, it is { "name" : "xyz", "age" : 12 } and in other { "company_name" : "pqr", "address" : "some_address" } If I get the data via the msg.data then I need to parse it. Other option is to use mapping but seems it is not possible as function argument.
    – Kumar
    May 30, 2018 at 6:26
  • 1
    Then, check out the JSON parser described in the Steemit article linked in my previous comment ( steemit.com/json/@chrisdotn/a-json-parser-for-solidity ). I have not used it but I read the article and it looks like what you need. May 30, 2018 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.