var jsObj: JsonObject; jsObj2: JsonObject; jsToken: JsonToken; jsToken2: JsonToken; jsToken3: JsonToken; jsToken4: JsonToken; jsArray: JsonArray; InStr: InStream; OutStr: OutStream; FileName: Text; tmpBlob: Codeunit "Temp Blob"; begin if UploadIntoStream('Load JSON File', '', '', FileName, InStr) then begin jsObj.ReadFrom(InStr); if jsObj.Get('transactions', jsToken) then begin if jsToken.IsArray then begin jsArray := jstoken.AsArray(); foreach jsToken2 in jsArray do begin if jsToken2.SelectToken('checkoutPaymentDetails', jsToken3) then if jstoken3.SelectToken('cardBin', jsToken4) then if jsToken4.IsValue then begin jsObj2 := jsToken3.AsObject(); jsObj2.Replace('cardBin', 'xxxx'); end; end; end; end; tmpBlob.CreateOutStream(OutStr); jsObj.WriteTo(OutStr); tmpBlob.CreateInStream(InStr); FileName := 'output.json'; DownloadFromStream(InStr, '', '', '', FileName); end; end;
tmpBlob: Codeunit "Temp Blob"; tmpBlob.CreateOutStream(OutStr); tmpBlob.CreateInStream(InStr);
tmpBlob: Record TempBlob; tmpBlob.Blob.CreateOutStream(OutStr); tmpBlob.Blob.CreateInStream(InStr);
Answers
Below is the JSON. I would like to mask the following keys:
1) cardBin
2) cardLast4
3) cardExpiryMonth
4) cardExpiryYear
What I have now is something like below but doesn't seem to do what I want.
JSON example:
For this particular case you can do somethong like this:
I copy paste your json data into a file that is loaded with the UploadIntoStream function.
I am using a BC 15 version, so if this code:
Doesn't work in your instalation change it to this:
Regards
Edited my post and somehow it mysteriously dissapeared
Anyway my question was I need to mask 3 other fields. Can I re-use the same objects? i.e:
Yes, you can do that but check out the names of the keys that you want to change because in your initial json data they are "cardExpiryMonth" not "experyMonth" and so on.
It was a typo in my earlier reply, sorted it and all working now