Skip to main content

Hello, this is the output (GeoJSON) I would like to create

Right now I have the alias data in a table format like this and all the other data in another table. How can I create that JSON array shown above ? I use a GeoJSON writer in the end. What type should be used for the alias attribute?

ID

 

Code

 

Name

 

85908

 

null

 

Ab

 

85908

 

PP

 

Hg

 

85909

 

OO

 

Gtu

 

85909

 

QQ

 

KU

 

A possible way I can think of is:

  1. Use a FeatureWriter (format is GeoJSON) to write the features without the "Alias" arrays into a GeoJSON file.
  2. Read back the GeoJSON and decompose it into individual feature objects (JSON fragments), with the JSONFragmenter.
  3. On the other hand, create the JSON arrays (pairs of Code and Name) for each ID.
  4. Use a JSONUpdater to insert the JSON array as "Alias" into "properties" object under the feature object which has the same ID.
  5. Re-construct a GeoJSON document from the updated feature objects, with the JSONTemplater.
  6. Finally write the GeoJSON document into a file with the Text File writer.

... it's hard to explain all with my poor English. Please see the attached workspace example.

insert-array-into-geojson-property.fmwt (FME 2019.0.1)

 


A possible way I can think of is:

  1. Use a FeatureWriter (format is GeoJSON) to write the features without the "Alias" arrays into a GeoJSON file.
  2. Read back the GeoJSON and decompose it into individual feature objects (JSON fragments), with the JSONFragmenter.
  3. On the other hand, create the JSON arrays (pairs of Code and Name) for each ID.
  4. Use a JSONUpdater to insert the JSON array as "Alias" into "properties" object under the feature object which has the same ID.
  5. Re-construct a GeoJSON document from the updated feature objects, with the JSONTemplater.
  6. Finally write the GeoJSON document into a file with the Text File writer.

... it's hard to explain all with my poor English. Please see the attached workspace example.

insert-array-into-geojson-property.fmwt (FME 2019.0.1)

 

Alternative. This is an advanced use of the JSONTemplater.

build-geojson-with-jsontemplater.fmwt (FME 2019.0.1)


A possible way I can think of is:

  1. Use a FeatureWriter (format is GeoJSON) to write the features without the "Alias" arrays into a GeoJSON file.
  2. Read back the GeoJSON and decompose it into individual feature objects (JSON fragments), with the JSONFragmenter.
  3. On the other hand, create the JSON arrays (pairs of Code and Name) for each ID.
  4. Use a JSONUpdater to insert the JSON array as "Alias" into "properties" object under the feature object which has the same ID.
  5. Re-construct a GeoJSON document from the updated feature objects, with the JSONTemplater.
  6. Finally write the GeoJSON document into a file with the Text File writer.

... it's hard to explain all with my poor English. Please see the attached workspace example.

insert-array-into-geojson-property.fmwt (FME 2019.0.1)

 

Thank you so much, @takashi. It works perfectly!


A possible way I can think of is:

  1. Use a FeatureWriter (format is GeoJSON) to write the features without the "Alias" arrays into a GeoJSON file.
  2. Read back the GeoJSON and decompose it into individual feature objects (JSON fragments), with the JSONFragmenter.
  3. On the other hand, create the JSON arrays (pairs of Code and Name) for each ID.
  4. Use a JSONUpdater to insert the JSON array as "Alias" into "properties" object under the feature object which has the same ID.
  5. Re-construct a GeoJSON document from the updated feature objects, with the JSONTemplater.
  6. Finally write the GeoJSON document into a file with the Text File writer.

... it's hard to explain all with my poor English. Please see the attached workspace example.

insert-array-into-geojson-property.fmwt (FME 2019.0.1)

 

Hello @takashi, I applied the same fme script to another case. I am wondering where I can specify the data type of the attributes in the array? By default there are all string but I want to change some to int. Where can I do it? Thx.


Hello @takashi, I have a second question. One attribute (called Description) of the original Json file (the one that goes through FeatureWriter and then FeatureReader; not part of the array) is in xml format e.g. "Description" : "<?xml version="1.0" encoding="UTF-16"?><p>An object exists in position 34&deg 45' 28" N 131&deg 51' 28" E (WGS84 Datum).</p>" The FeatureWriter and then FeatureReader works perfectly but after the JSONUpdater transformer this attribute looks like "Description" : "<p>An object exists in position 34&deg 45' 28" N 131&deg 51' 28" E (WGS84 Datum).</p>". How can I keep the xml version part of the beginning? Thx again.


A possible way I can think of is:

  1. Use a FeatureWriter (format is GeoJSON) to write the features without the "Alias" arrays into a GeoJSON file.
  2. Read back the GeoJSON and decompose it into individual feature objects (JSON fragments), with the JSONFragmenter.
  3. On the other hand, create the JSON arrays (pairs of Code and Name) for each ID.
  4. Use a JSONUpdater to insert the JSON array as "Alias" into "properties" object under the feature object which has the same ID.
  5. Re-construct a GeoJSON document from the updated feature objects, with the JSONTemplater.
  6. Finally write the GeoJSON document into a file with the Text File writer.

... it's hard to explain all with my poor English. Please see the attached workspace example.

insert-array-into-geojson-property.fmwt (FME 2019.0.1)

 

Hello @takashi, I have a second question. One attribute (called Description) of the original Json file (the one that goes through FeatureWriter and then FeatureReader; not part of the array) is in xml format e.g. "Description" : "<?xml version="1.0" encoding="UTF-16"?><p>An object exists in position 34&deg 45' 28" N 131&deg 51' 28" E (WGS84 Datum).</p>" The FeatureWriter and then FeatureReader works perfectly but after the JSONUpdater transformer this attribute looks like "Description" : "<p>An object exists in position 34&deg 45' 28" N 131&deg 51' 28" E (WGS84 Datum).</p>". How can I keep the xml version part of the beginning? Thx again.


Reply