|  | 
 
  
    | RSS Feed - WebSphere MQ Support | RSS Feed - Message Broker Support |  
 
  
	|    |  |  
  
	| Mapping a JSON field | « View previous topic :: View next topic » |  
  	| 
		
		
		  | Author | Message |  
		  | petervh1 | 
			  
				|  Posted: Wed Jul 06, 2022 5:38 am    Post subject: Mapping a JSON field |   |  |  
		  | Centurion
 
 
 Joined: 19 Apr 2010Posts: 140
 
 
 | 
			  
				| Hi 
 I have a basic question. Should be obvious, but I just can't find it.
 
 I'm trying to determine whether a particular field in a JSON input message exists or not. The field is called ObjectID.
 
 The Trace node shows the data as
 
 
 
   
	| Code: |  
	| (0x01000000:Object):JSON               = ( ['json' : 0x7f66a1af8720] (0x01000000:Object):Data = (
 (0x01000000:Object):d = (
 (0x01001000:Array):results = (
 (0x01000000:Object):Item = (
 (0x01000000:Object   ):__metadata = (
 (0x03000000:NameValue):uri  = 'https://xxx('00163E1CA6AA1EE798907658744CED4F')' (CHARACTER)
 (0x03000000:NameValue):type = 'cust.StoreRoot' (CHARACTER)
 )
 (0x03000000:NameValue):ObjectID   = '00163E1CA6AA1EE798907658744CED4F' (CHARACTER)
 )
 |  
 I even wrote the JSON structure to a queue and viewed it using RFHUTIL:
 
 
 
   
	| Code: |  
	| d.results.__metadata[1].uri="https:\/\/xxx\/xxx\/xxx\/xxx\/xxx\/xx\/xxx\/xxx('00163E1CA6AA1EE798907658744CED4F')" d.results.__metadata[1].type="cust.StoreRoot"
 d.results.,"ObjectID"[1]="00163E1CA6AA1EE798907658744CED4F"
 |  
 In my ESQL: I have:
 
 
 
 
   
	| Code: |  
	| DECLARE ObjectIDExists BOOLEAN EXISTS(InputRoot.JSON.Data.d.results.",ObjectID".[]); |  
 I've tried numerous combinations but can't seem to match the field.
 
 TIA
 |  |  
		  | Back to top |  |  
		  |  |  
		  | abhi_thri | 
			  
				|  Posted: Wed Jul 06, 2022 10:55 pm    Post subject: |   |  |  
		  |  Knight
 
 
 Joined: 17 Jul 2017Posts: 516
 Location: UK
 
 | 
			  
				| hi...why is ',' appearing before 'ObjectIdD'?...is it part of the field name? 
 try the below and see...
 
 
 
   
	| Code: |  
	| IF FIELDNAME(InputRoot.JSON.Data.d.results.ObjectID) IS NOT NULL |  
 or
 
 
 
   
	| Code: |  
	| IF FIELDNAME(InputRoot.JSON.Data.d.results.",ObjectID") IS NOT NULL |  |  |  
		  | Back to top |  |  
		  |  |  
		  | petervh1 | 
			  
				|  Posted: Wed Jul 06, 2022 11:06 pm    Post subject: |   |  |  
		  | Centurion
 
 
 Joined: 19 Apr 2010Posts: 140
 
 
 | 
			  
				| I was also surprised to see the ',' in the RFHUTIL representation. It's definitely there - not a typo on my part. 
 I ignored that, and coded as per your first suggestion and it worked.
 
 Thanks
 |  |  
		  | Back to top |  |  
		  |  |  
		  | timber | 
			  
				|  Posted: Thu Jul 07, 2022 4:59 am    Post subject: |   |  |  
		  |  Grand Master
 
 
 Joined: 25 Aug 2015Posts: 1292
 
 
 | 
			  
				| This should also work, and may be a little easier to remember: 
 
   
	| Code: |  
	| IF EXISTS(InputRoot.JSON.Data.d.results.ObjectID[])
 ...
 END IF
 
 |  
 Don't forget the [] after the field reference - the EXISTS function only works with arrays.
 |  |  
		  | Back to top |  |  
		  |  |  
		  | missing_link | 
			  
				|  Posted: Fri Jul 08, 2022 7:10 am    Post subject: |   |  |  
		  |  Acolyte
 
 
 Joined: 08 Jan 2004Posts: 61
 
 
 | 
			  
				| (Long time since I've been here) - but glad i saw this post earlier...seeing the exact same thing with comma's in the RFHUtil JSON view, which made think wha... for minute.  Must just be the way it representing the JSON Output. |  |  
		  | Back to top |  |  
		  |  |  
		  |  |  |  
  
	|    |  | Page 1 of 1 |  
 
 
  
  	| 
		
		  | 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 
 |  |  |  |