Skip to main content

I am trying to generate a JSON message to update editing templates on an AGOL Feature Service. I've got most of it complete. I am having trouble with the last piece though.

 

Each Editing Template has a list of fields and defaults like this:

JSONIssue_Screenshot1I am trying to generate 27 unique editing templates based on unique pairs of 2 attributes. The portion of the JSON text I am struggling with is the "types"]]"templates"]]"prototype"]]"attributes"] section. I have the correct number of "types" (27). I have the correct fields and corresponding default values.

 

JSONIssue_CurrentResultsAs you can see, I am getting an extra pair of "},{" between each field as compared to the example above. Almost like each row is it's own unique element. I am sending 594 features into the "EDITEMPLATEFIELDS" sub template and grouping the process by '_editTemplatePairs' attribute as these contain 27 unique field configurations for all 22 fields in the editing template.

 

I am leveraging Sub Templates in the JSONTemplater. Here's how I currently have this section set up:

 

ROOT: (Number of Incoming Features: 1)

JSONIssue_JSONTemplator_ROOTSub Template: EDITTYPES (Number of Incoming Features: 27)

JSONIssue_JSONTemplator_SUB_EDITTYPESSub Template: EDITEMPLATEFIELDS (Number of Incoming Features: 594)

JSONIssue_JSONTemplator_SUB_EDITEMPLATEFIELDSI can't seem to get the JSONTemplator to ignore the 'array' function. Ultimately, I have 27 different variations of these sets of fields:

JSONIssue_ExampleOfFieldsAny suggestions on how to remove the 'Array' syntax in the t"prototype"]o"attributes"] section? I've tried playing around with lists and pre-formatting JSON text, but have gotten no where. I'm sure I'm missing some very simple here.

 

Unfortunately, I won't be able to upload my workspace as the services I am trying to update cannot be shared publicly.

 

FME Version: 2020.1.3.0 (20201001 - Build 20632)

 

Thanks in advance!

-Mark

 

Not a real solution exactly, however, something that I find quite helpful is a combination of an attribute creator to built the strings so:

 

_attribute = "@Value(_jsonPrototype_AttributeName)" : "@Value(_jsonPrototype_AttributeValue)"

 

This will give you an attribute formatted for one line of the json.

 

Next use an Aggregator to combine the attributes into a single string blob:

Attributes to concatenate: _attribute

Separator Character: ,\\n (where "\\n" is a new line character available in the Special Characters section in the text editor)

 

You'll then have a blob of text formatted inside one attribute that you can just stick in.

 

It's not exactly a clean method or elegant but it should work as a quick work around.

 

The Json and xml templators are really powerful but there seems to be a lot of hidden undocumented features, sometimes a workaround is the quickest approach until you learn how to do it the 'proper' way


Not a real solution exactly, however, something that I find quite helpful is a combination of an attribute creator to built the strings so:

 

_attribute = "@Value(_jsonPrototype_AttributeName)" : "@Value(_jsonPrototype_AttributeValue)"

 

This will give you an attribute formatted for one line of the json.

 

Next use an Aggregator to combine the attributes into a single string blob:

Attributes to concatenate: _attribute

Separator Character: ,\\n (where "\\n" is a new line character available in the Special Characters section in the text editor)

 

You'll then have a blob of text formatted inside one attribute that you can just stick in.

 

It's not exactly a clean method or elegant but it should work as a quick work around.

 

The Json and xml templators are really powerful but there seems to be a lot of hidden undocumented features, sometimes a workaround is the quickest approach until you learn how to do it the 'proper' way

@virtualcitymatt​ Thanks! That's a nice little trick to add to my bag. I modified it a little. Like you said, not pretty, but gets the results I need. I'm sure there is a more elegant way to get to the same endpoint.

 

I'm documenting my final solution here in case someone else runs into the same issue:

 

First, I had to account for empty/null attributes. I used a conditional statement when creating the '_attributes' attribute that was mentioned above. Here's what I did:

JSONIssue_Fix_ConditionalStatementNext, in the aggregator, I had to set the GroupBy parameter and I did not include the "\\n" in the Separator Character like this:

JSONIssue_Fix_AggregatorSettingsNext, I had to append a "{" to the beginning of the aggregator output and a "}" to the end of the same output like this in an AttributeCreator as the JSONTemplater wasn't putting them in the correct position.

JSONIssue_Fix_AddBracketsThe final JSON text looks like this before going to the JSON Templater:

JSONIssue_Fix_FinalTextBeforeJSONTemplaterNext, I modified the "EDITTYPES" & "EDITTEMPLATEFIELDS Sub Templates in the JSONTemplater as shown below:

JSONIssue_Fix_ChangeToSubTemplate-EDITTYPESJSONIssue_Fix_ChangeToSubTemplate-EDITTEMPLATEFIELDSThe final result looks like this:

JSONIssue_Fix_ResultsThanks again for your help @virtualcitymatt​ Hopefully this helps someone else dealing with the unique JSON formatting of feature services.

 

 

 

 

 


Reply