Skip to main content
Question

Exposing attributes from GeoJSON


fmeuser_gc
Contributor
Forum|alt.badge.img+8

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

david_r
Evangelist
  • April 11, 2018

Try the following JSON query:

json["features"][*]["properties"]

fmeuser_gc
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • April 11, 2018

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


david_r
Evangelist
  • April 12, 2018
fmeuser_gc wrote:

@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?

danilo_fme
Evangelist
Forum|alt.badge.img+43
  • Evangelist
  • April 12, 2018
david_r wrote:
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

fmeuser_gc
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • April 12, 2018
danilo_fme wrote:
@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.

 


fmeuser_gc
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • April 12, 2018

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


david_r
Evangelist
  • April 12, 2018

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

 


rylanatsafe
Safer
Forum|alt.badge.img+13

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


rylanatsafe
Safer
Forum|alt.badge.img+13
david_r wrote:

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".

 

 


fmeuser_gc
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • April 12, 2018
david_r wrote:

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?

danilo_fme
Evangelist
Forum|alt.badge.img+43
  • Evangelist
  • April 12, 2018
fmeuser_gc wrote:
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 :)

 

 


fmeuser_gc
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • April 12, 2018
rylanatsafe wrote:

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

 

 

 


rylanatsafe
Safer
Forum|alt.badge.img+13
fmeuser_gc wrote:
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?

 


fmeuser_gc
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • April 12, 2018
rylanatsafe wrote:
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

 


rylanatsafe
Safer
Forum|alt.badge.img+13
fmeuser_gc wrote:
@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.

 


fmeuser_gc
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • April 12, 2018
fmeuser_gc wrote:
@RylanAtSafe - I have same version installed with same build 15575

 

Can you please attach 2015 version workspace?

 

 


rylanatsafe
Safer
Forum|alt.badge.img+13
fmeuser_gc wrote:
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

 


takashi
Influencer
  • April 12, 2018
rylanatsafe wrote:

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

david_r
Evangelist
  • April 13, 2018
fmeuser_gc wrote:
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.

david_r
Evangelist
  • April 13, 2018

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


rylanatsafe
Safer
Forum|alt.badge.img+13
takashi wrote:
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


takashi
Influencer
  • April 15, 2018
takashi wrote:
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.

fmeuser_gc
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • April 15, 2018
takashi wrote:
@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

takashi
Influencer
  • April 15, 2018

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"][*]

fmeuser_gc
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • April 15, 2018
takashi wrote:

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.

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings