Retrieving and Saving JSON Data Using Formula in EspoCRM

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sapyantuk
    Senior Member
    • Oct 2020
    • 265

    Retrieving and Saving JSON Data Using Formula in EspoCRM

    Hello EspoCRM Developers,

    I have a text field in which JSON data is stored. The data is structured like this:
    {
    "employee": {
    "name": "sonoo",
    "salary": 56000,
    "married": true
    }
    }



    I would like to know if there's a way to use the json\retrieve function in a formula to extract the name, salary, and married values from this JSON and save them to their respective fields within the same record.

    Note: The JSON data is stored in the text field of the same record.

    Thank you for your assistance!

  • emillod
    Active Community Member
    • Apr 2017
    • 1405

    #2
    Hello sapyantuk
    i don't know whether it's a real example, but you should play with it in the Sandbox Formula tool, which is available in Administration section.
    I assume based on your post that you have multiple employees in one json. Please check the documentation, there is different example for {} and for [{}].
    json - EspoCRM Documentation

    I assume you should try:
    $value = json\retrieve(fieldNameWithJson, 'employee.name');

    Comment


    • esforim
      esforim commented
      Editing a comment
      That cool, was JSON formula recently added?
  • emillod
    Active Community Member
    • Apr 2017
    • 1405

    #3
    esforim i don't think so? We're using object/json formulas in workflows, when submission from any of our forms comes to Espo. I think it was added in version 7.x?

    Comment

    Working...