Ask Your Question
1

How to pass mongodb record to http client post as valid JSON

asked 2018-12-05 03:03:57 -0600

Carlo gravatar image

I have a mongoDB origin (not oplog, the regular one), followed by a Http Client (Processor). The goal is to read every JSON document from the mongodb, and for each one, call a REST service.

The rest service works, I can test that separately with Postman, and get proper results. I put the 'http method' to POST, and for the request body enter ${record:value('/')}. I leave Default Request Content Type as 'application/json'.

On the receiving end, I do get the entire record, but not as a valid json. My REST service shows that what I receive is something like this:

[Field[MAP:{key1=Field[LIST:[key2=Field[MAP:{key3=Field[STRING:value1]}]]], key4=Field[LIST:[Field[MAP:{key5=Field[LIST:[Field[MAP:{key6=Field[STRING:value2]}]]]}]]]}]]

while it should be:

{ "key1": 
  [{"key2": 
    [{"key3": "value01"}],
  "key4": 
     [{"key5": 
       [ {"key6": "value02"}]
     }]
   }]
}

How would I be able to pass a valid JSON ? I see 2 possibilities:

  1. Is there something special I can put in http client - http request body (${record:value('/')}.toJson would be lovely)

  2. Is there an processor I can put between my mongodb and http client that would transform it ?

Sorry for the lack of pics, too little points here.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-12-05 13:43:49 -0600

metadaddy gravatar image

You can use the Data Generator processor to do this. Set the Target Field to some desired value, such as /json, set Output Type to String, and set Data Format to JSON:

image description

Now you can use that field in the HTTP Client with ${record:value('/json')}

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-12-05 03:03:57 -0600

Seen: 29 times

Last updated: Dec 05