Skip to main content

Hello all,

I have a Workspace that makes the reverse geocoding using PythonCaller.

import fme

import fmeobjects

import json ,urllib2
#

def processFeature(feature):

att = urllib2.urlopen('http://maps.googleapis.com/maps/api/geocode/json?latlng=-23.2186725,-45.9056706')

data = json.load(att)

print "o json é ", data

When i run my workspace i see the results on the log file because i put the Print:


How can i get this result with a new attribute?

Thanks in Advance,

Danilo de Lima

Try something like

feature.setAttribute('myJSON', json.dumps(data))

You can then use the regular FME JSON transformers to work on the new attribute "myJSON".

David


hello @david_r thanks your help. Its works!!!

Amazing. 🙂 The secrets is the json.dumps, other?

Thanks in Advance,

Danilo de Lima


hello @david_r thanks your help. Its works!!!

Amazing. 🙂 The secrets is the json.dumps, other?

Thanks in Advance,

Danilo de Lima

@david_r Thanks the explanation and the link.


hello @david_r thanks your help. Its works!!!

Amazing. 🙂 The secrets is the json.dumps, other?

Thanks in Advance,

Danilo de Lima

Look in the Python json module documentation. Basically:

 

.dumps() transforms a string into a Python dictionary

 

.loads() transforms a Python dictionary into a string

 

 


Try something like

feature.setAttribute('myJSON', json.dumps(data))

You can then use the regular FME JSON transformers to work on the new attribute "myJSON".

David

Hi David, 

in 2024.2 I have json that I dump into text as you suggested.

feature.setAttribute("output_result", json.dumps(results))

Then I have attribute exposed, but not sure why it keeps coming out as <missing> . Also not sure what data type to use since simple text option does not exist.

 


I am successfully printing data, just no luck outputting into attribute:

 



EDIT: my error was self.pyoutput(feature, output_tag="PYOUTPUT") placement. Moving it to the bottom of input function solved all the problems…. 🤓


Reply