Question

Bson (Binary Json) to Json conversion

  • 28 April 2023
  • 3 replies
  • 79 views

Hey Everyone,

I am a newbie in FME wonderland can anyone help me out how can I convert bson to json.

I am using http caller to get data from our asset management system named Alloy by Causeway. Al the data is in bson format and i don't know how can I convert that into usable format.

All the data is sitting under _response_body.

Let me know if anyone can help or want any more details :)


3 replies

Userlevel 3
Badge +17

Hello @jigar.bhojak​ 

Unfortunately, there does not appear to be a transformer that natively supports converting BSON to JSON in FME.

If you are comfortable using Python, it is possible to install the bson Python library following the instructions here. This should allow you to convert BSON into JSON strings using the PythonCaller. I have attached an example workspace demonstrating this workflow and I hope it helps.

Hello @jigar.bhojak​ 

Unfortunately, there does not appear to be a transformer that natively supports converting BSON to JSON in FME.

If you are comfortable using Python, it is possible to install the bson Python library following the instructions here. This should allow you to convert BSON into JSON strings using the PythonCaller. I have attached an example workspace demonstrating this workflow and I hope it helps.

Thank you, Debbie,

I tried the transformer you have attached but I think our data is acting like special privilege kid and not responding to it 😆

Will have to try something else :(

thank you for your help anyway :)

Badge +5

Thank you, Debbie,

I tried the transformer you have attached but I think our data is acting like special privilege kid and not responding to it 😆 

Will have to try something else :(

thank you for your help anyway :)

Hey follow the instructions for installing bson here: Installing Python Packages to FME Desktop (safe.com)

I can recommend using the following command on windows:

fme.exe python -m pip install bson -t %USERPROFILE%\Documents\FME\Plugins\Python\Python39

Now open the pythoncaller in debbies answer, go to line 15 and make the following change:

json_dict = bson.loads(feature.getAttribute("_response_body"))

connect this transformer to the output of httpcaller.

 

if you get an error: Python Exception <ModuleNotFoundError>: No module named 'bson'

 

you can at line 3 add 

import sys
sys.path = [r'C:\Users\<username>\Documents\FME\Plugins\Python\Python39'] + sys.path

 

Change <username> with your username.

 

Hope this helps.

Reply