I have a field which has the JSON string. I just need to populate a part of that string into different field is that possible?

log__c = JSON={"eventPayload":{"units":1.00,"name":"D-00889","applied_for":null}

I just want to display D-00889 in a new field, how can we do this.

Hope I am clear, thanks.


Probably easiest and still kinda smart way to do it is to use JSON2Apex (provide there you're example JSON) that way you'll have data structure into which you can deserialize given JSON using

JSON2Apex obj = (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);

After that you can just get that field by simple reference.

  • can we do it using a workflow or formula field, Log__c is a text field – Sfdc learner Oct 12 '18 at 15:59
  • You can't parse JSON using workflow rule and using formula is not a good idea (i think it could be possible using regexp though). Still I dont see why Log__c being a text field is a problem? It would deserialize to an object with fields that would be a string so you will just need to do something like log__c = obj.eventPayload.name and you'll have your result – user1974566 Oct 12 '18 at 16:03

It seems like this string is saved in a field.

Assuming the string is like below which is not a valid JSON string too: {"eventPayload":{"units":1.00,"name":"D-00889","applied_for":null}

Even though using a wrapper class is recommended, if you have really wanted to use a formula, assuming your string never changes that much and you name is always 7 characters you can use this formula:

MID(Log__c, FIND("name", Log__c)+ 7 , 7)

This will give you: D-00889

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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