How to search in JSON object

I have my json file save with below data in it -
{
“AttachmentsList”: [
{
“fileName”: “trade-inv-posting.pdf”,
“emailDate”: “Fri, 30 Apr 2021 04:22:04 +0000 (UTC)”,
“emailFrom”: “noreply@noreply”,
“emailSubject”: “New document is posted by xyz”,
“emailBody”: “<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>Company Code : 50X
Invoice Date Override : 4/28/2021
Vendor : SILVER UNIVERSAL
Requestor : xyz.bcd@test.com

},
{
“fileName”: “ABC#2021.04.30.pdf;3 way check INV & PL HX201002 ci.pdf”,
“emailDate”: “Thu, 22 Apr 2021 10:44:17 +0000 (UTC)”,
“emailFrom”: “noreply@noreply.cloud”,
“emailSubject”: “New document is posted by abc”,
“emailBody”: “<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8”>Company Code : 51X
Invoice Date Override : 4/21/2021
Vendor : GUANG LTD
Requestor : abc.xyz@test.com

}
]
}

I need to find match for fileName “ABC#2021.04.30.pdf” in AttachmentsList and save Invoice Date Override, Vendor and Requestor for that match in variable (later to save in another system).

I am using below code but it doesn’t work for me -

Dim emailInvoiceData As JObject = New JObject
' Check if Downloaded Invoice Folder exists
If (Directory.Exists(Path.GetFullPath(Config("InputInvoiceDir").ToString))) Then
	' Check for 'emailData.json' file exists
	If (File.Exists(Path.Combine(Path.GetFullPath(Config("InputInvoiceDir").ToString), Config("EmailInvoiceDataFileName").ToString))) Then
		' Read file and parse json object
		Dim emailDataStr As String = File.ReadAllText(Path.Combine(Path.GetFullPath(Config("InputInvoiceDir").ToString), Config("EmailInvoiceDataFileName").ToString))
		If (Not String.IsNullOrWhiteSpace(emailDataStr)) Then
			emailInvoiceData = JsonConvert.DeserializeObject(Of JObject)(emailDataStr)			
		End If
		' Check for AttachmentsList JArray exists
	'	If ((emailInvoiceData("AttachmentsList") IsNot Nothing) AndAlso (emailInvoiceData("AttachmentsList").Value(Of JArray).Count > 0)) Then
	'		For Each fileDetails As JObject In (emailInvoiceData("AttachmentsList").Value(Of JArray)) 
	'	
	'		Next			
	'	End If		
	End If
	
End If

Hi,
watch this:

Thanks a lot Adrian. This worked for me.

Although code inside InvoiceCode didn’t work but DeserializeJson activity worked for me.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.