Question

Exposing attributes from GeoJSON


Badge +6

I'm trying to expose attribute only 'fill-opacity' from the below json.

{"type":"FeatureCollection","features":[{"geometry":{"type":"Polygon","coordinates":[[[-81.0007,29.2057],[-81.0055,29.2029],[-81.0105,29.205],[-81.0107,29.2097],[-81.0059,29.2125],[-81.0009,29.2104],[-81.0007,29.2057]]]},"type":"Feature","properties":{"stroke-opacity":0.9,"fill-opacity":0.9,"hail_size_in_int":0.5,"hail_size_in":"0.5-0.9 inches","stroke-width":0,"fill":"#FFFFC0"}}]}

It returns blank values. Can someone please help me ?


25 replies

Userlevel 4

Try the following JSON query:

json["features"][*]["properties"]
Badge +6

@david_r - No, it doesn't work. It still have blank values.

Userlevel 4

@david_r - No, it doesn't work. It still have blank values.

I tested using FME 2017.1 and it worked fine with the json above.

 

Could you perhaps post a sample workspace that demonstrates the issue?
Userlevel 4
Badge +30
I tested using FME 2017.1 and it worked fine with the json above.

 

Could you perhaps post a sample workspace that demonstrates the issue?
@david_r and @fmeuser_gc I tested with succefull in FME 2018. Good job @david_r
Badge +6
@david_r and @fmeuser_gc I tested with succefull in FME 2018. Good job @david_r
@danilo_fme , @david_r - This still doesn't work. I'm using 2015.1 version. Can you please add workspace.

 

Badge +6

Tagging in @takashi, @TiaAtSafe, @RylanAtSafe, @erik_jan

Userlevel 4

I just tested with FME 2015.1.0.3 and it works fine.

Try the attached minimal workspace. If it works for you, the problem could be something else entirely.

jsonfragmenter.fmwt

 

Badge +11

I couldn't get the example to work with "properties" in the query – instead I had to use it as a prefix in the attributes to expose:

JSON Query: json["features"][*]

 

Attributes to Expose: properties.fill-opacity

Edit: Tested in FME 2018.0 Build 18295 macOS

Badge +11

I just tested with FME 2015.1.0.3 and it works fine.

Try the attached minimal workspace. If it works for you, the problem could be something else entirely.

jsonfragmenter.fmwt

 

This also works in 2018.0 Build 18295 with JSONFragmenter Version 3 and after upgrading it to Version 7! I must have had a syntax issue when I tested with "properties".

 

 

Badge +6

I just tested with FME 2015.1.0.3 and it works fine.

Try the attached minimal workspace. If it works for you, the problem could be something else entirely.

jsonfragmenter.fmwt

 

This still doesn't work in 2015.1.3 version. But it is working in 2017.1 version.

 

Will there be any different syntax in 2015.1 version?
Userlevel 4
Badge +30
This still doesn't work in 2015.1.3 version. But it is working in 2017.1 version.

 

Will there be any different syntax in 2015.1 version?
Good news :)

 

 

Badge +6

I couldn't get the example to work with "properties" in the query – instead I had to use it as a prefix in the attributes to expose:

JSON Query: json["features"][*]

 

Attributes to Expose: properties.fill-opacity

Edit: Tested in FME 2018.0 Build 18295 macOS

This syntax doesn't work in 2015.1.3 version. I still get blank values with the above syntax

 

 

 

Badge +11
This syntax doesn't work in 2015.1.3 version. I still get blank values with the above syntax

 

 

 

Hmm, that's very strange that the FME 2015.1.3 install will not work with either JSON Query posted as comments. Looking at the changelog nothing is jumping out at me to explain this behaviour..

 

I tested on 2015.1.3.2 Build 15575 and it works. What build do you have installed, @fmeuser_gc?

 

Badge +6
Hmm, that's very strange that the FME 2015.1.3 install will not work with either JSON Query posted as comments. Looking at the changelog nothing is jumping out at me to explain this behaviour..

 

I tested on 2015.1.3.2 Build 15575 and it works. What build do you have installed, @fmeuser_gc?

 

@RylanAtSafe - I have same version installed with same build 15575

 

Badge +11
@RylanAtSafe - I have same version installed with same build 15575

 

I tested in Win32 and Win64 – both give correct results. Perhaps try reinstalling FME 2015.1.3.2 if you have a requirement to use that version?

 

https://www.safe.com/support/support-resources/fme-downloads/archived/

 

 

If the issue persists, you may consider contacting Safe Support for a more thorough investigation.

 

Badge +6
@RylanAtSafe - I have same version installed with same build 15575

 

Can you please attach 2015 version workspace?

 

 

Badge +11
Can you please attach 2015 version workspace?

 

 

I just used the template shared by david_r – but saved it in 15575 and attached here. jsonfragmenter-15575.fmw

 

Userlevel 2
Badge +17

I couldn't get the example to work with "properties" in the query – instead I had to use it as a prefix in the attributes to expose:

JSON Query: json["features"][*]

 

Attributes to Expose: properties.fill-opacity

Edit: Tested in FME 2018.0 Build 18295 macOS

When you set GEOJSON to the 'Explode as Format ' parameter, the JSONFragmenter attempts to fragment the source JSON document into individual Features

 

{
   "geometry" : {
      "type" : "Polygon",
      "coordinates" : [ ... ]
   },
   "type" : "Feature",
   "properties" : {
      "stroke-opacity" : 0.9,
      "fill-opacity" : 0.9,
      "hail_size_in_int" : 0.5,
      "hail_size_in" : "0.5-0.9 inches",
      "stroke-width" : 0,
      "fill" : "#FFFFC0"
   }
}
and then flatten the "properties" object. In this case, strictly saying, the JSON query should be this one which fragments the source JSON document into individual GeoJSON Features.

 

json["features"][*]
However, even if you have set GEOJSON to the 'Explode as Format' parameter, FME seems to treat the parameter as JSON when the JSON query is not correct to fragment the source document into GeoJSON Features. Result, this query could also return the expected result.

 

json["features"][*]["properties"]
 Probably you find this warning message on the Translation Log.

 

JSONFragmenter(JSONQueryFactory): The JSON text could not be parsed as 'GEOJSON', parsing as plain JSON instead
I suspect that a specific build of FME won't perform the automatic reinterpretation on the 'Explode as Format'. Could you check this? @RylanAtSafe
Userlevel 4
This still doesn't work in 2015.1.3 version. But it is working in 2017.1 version.

 

Will there be any different syntax in 2015.1 version?
The syntax should be the same in all FME versions, as long as there isn't a bug in that particular version.
Userlevel 4

Inspired by the comment from @takashi here, what happens if you set Explode as format = JSON rather than GEOJSON?

Badge +11
When you set GEOJSON to the 'Explode as Format ' parameter, the JSONFragmenter attempts to fragment the source JSON document into individual Features

 

{
   "geometry" : {
      "type" : "Polygon",
      "coordinates" : [ ... ]
   },
   "type" : "Feature",
   "properties" : {
      "stroke-opacity" : 0.9,
      "fill-opacity" : 0.9,
      "hail_size_in_int" : 0.5,
      "hail_size_in" : "0.5-0.9 inches",
      "stroke-width" : 0,
      "fill" : "#FFFFC0"
   }
}
and then flatten the "properties" object. In this case, strictly saying, the JSON query should be this one which fragments the source JSON document into individual GeoJSON Features.

 

json["features"][*]
However, even if you have set GEOJSON to the 'Explode as Format' parameter, FME seems to treat the parameter as JSON when the JSON query is not correct to fragment the source document into GeoJSON Features. Result, this query could also return the expected result.

 

json["features"][*]["properties"]
 Probably you find this warning message on the Translation Log.

 

JSONFragmenter(JSONQueryFactory): The JSON text could not be parsed as 'GEOJSON', parsing as plain JSON instead
I suspect that a specific build of FME won't perform the automatic reinterpretation on the 'Explode as Format'. Could you check this? @RylanAtSafe
@takashi - Testing with Build 15575 Win64 and 'Explode as Format' set to GEOJSON displays the warning, but the translation is successful and the fill-opacity is correctly exposed and populated with value.

 

0684Q00000ArNDGQA3.png

Userlevel 2
Badge +17
When you set GEOJSON to the 'Explode as Format ' parameter, the JSONFragmenter attempts to fragment the source JSON document into individual Features

 

{
   "geometry" : {
      "type" : "Polygon",
      "coordinates" : [ ... ]
   },
   "type" : "Feature",
   "properties" : {
      "stroke-opacity" : 0.9,
      "fill-opacity" : 0.9,
      "hail_size_in_int" : 0.5,
      "hail_size_in" : "0.5-0.9 inches",
      "stroke-width" : 0,
      "fill" : "#FFFFC0"
   }
}
and then flatten the "properties" object. In this case, strictly saying, the JSON query should be this one which fragments the source JSON document into individual GeoJSON Features.

 

json["features"][*]
However, even if you have set GEOJSON to the 'Explode as Format' parameter, FME seems to treat the parameter as JSON when the JSON query is not correct to fragment the source document into GeoJSON Features. Result, this query could also return the expected result.

 

json["features"][*]["properties"]
 Probably you find this warning message on the Translation Log.

 

JSONFragmenter(JSONQueryFactory): The JSON text could not be parsed as 'GEOJSON', parsing as plain JSON instead
I suspect that a specific build of FME won't perform the automatic reinterpretation on the 'Explode as Format'. Could you check this? @RylanAtSafe
@RylanAtSafe, from your testing result, the build 15575 too seems to treat the 'Explode as Format' with the same manner as other versions.

 

@fmeuser_gc, really strange if the JSON query they suggested doesn't work for your case. If the problem has not been resolved yet, I would recommend you to attach your workspace that reproduces the problem to your comment here, or send that to Safe support.
Badge +6
@RylanAtSafe, from your testing result, the build 15575 too seems to treat the 'Explode as Format' with the same manner as other versions.

 

@fmeuser_gc, really strange if the JSON query they suggested doesn't work for your case. If the problem has not been resolved yet, I would recommend you to attach your workspace that reproduces the problem to your comment here, or send that to Safe support.
@RylanAtSafe, @takashi, @david_r

 

Attached the workspace. I've used same queries provided by you, but get blank attribute values.

 

 

jsonfragment-test.fmw
Userlevel 2
Badge +17

Hi @fmeuser_gc, the response body from the HTTPCaller in your attached workspace (jsonfragment-test.fmw) looks like this.

{
   "code" : 200,
   "status" : "success",
   "data" : {
      "type" : "FeatureCollection",
      "features" : [
         {
            "geometry" : {
               "type" : "Polygon",
               "coordinates" : [
...

It's a JSON document which contains a GeoJSON "FeatureCollection" object as a member called "data". The structure is different from the GeoJSON document that you have pasted in your first question. That's the reason why nobody was able to find a correct JSON query.

If you want to extract individual GeoJSON features from the "data" object with the JSONFragmenter (Explode as Format: GEOJSON), you have to specify the correct path with the JSON query. Try this.

json["data"]["features"][*]
Badge +6

Hi @fmeuser_gc, the response body from the HTTPCaller in your attached workspace (jsonfragment-test.fmw) looks like this.

{
   "code" : 200,
   "status" : "success",
   "data" : {
      "type" : "FeatureCollection",
      "features" : [
         {
            "geometry" : {
               "type" : "Polygon",
               "coordinates" : [
...

It's a JSON document which contains a GeoJSON "FeatureCollection" object as a member called "data". The structure is different from the GeoJSON document that you have pasted in your first question. That's the reason why nobody was able to find a correct JSON query.

If you want to extract individual GeoJSON features from the "data" object with the JSONFragmenter (Explode as Format: GEOJSON), you have to specify the correct path with the JSON query. Try this.

json["data"]["features"][*]
Thank You everyone your your replies. It works now after @takashi identified an issue.

 

Reply