Skip to main content

Hello: I have a workspace that I attempted to write a JSON file with the JSON writer. The problem is, the structure of the JSON has a SUB associated with it and the SUB features are not produced with the write. I'm currently using the text file writer where it simply writes the text_line_data from my JSONFormatter. The problem with this approach is that the output are strings and I have some fields that must be numeric. I saw on another thread to dynamically convert the strings to int/double using the xs:int(attribute) or xs:double(attribute) function. This approach is fine BUT there are some number values that have NULL and in order to use the xs function, I've discovered these attributes can't be NULL. Can't I take care of this using the JSON writer by setting the datatype of the output? But again I can't seem to get the JSON writer to generate my SUB features.

The xs:interger function and the xs:double function convert <missing> attribute to null. Try changing every <null> and <empty> to <missing> with the NullAttributeMapper before the JSONTemplater.


@takashi - I had a NullAttributeMapper in there before the JSONTemplater but had all values checked (empty, missing, and null). I just made the adjustment you suggested and received these errors:

 

JSONTemplater(XMLTemplaterFactory): The following error occurred near line 5, column 35 of the query:

JSONTemplater(XMLTemplaterFactory): "xs:string": invalid value for cast/constructor: can not cast to "xs:double"

JSONTemplater(XMLTemplaterFactory): A fatal error has occurred. Check the logfile above for details

 

Here's what's in the JSONTemplater:

 

{

 

"totalInvestment": xs:double(fme:get-attribute("totalInvestment")),

 

"squareFootageRetail": xs:double(fme:get-attribute("squareFootageRetail")),

 

"squareFootageOffice": xs:double(fme:get-attribute("squareFootageOffice")),

 

"squareFootageManufacturing": xs:double(fme:get-attribute("squareFootageManufacturing")),

 

"recordType": fme:get-attribute("recordType"),

 

"projectStage": fme:get-attribute("projectStage"),

 

"projectName": fme:get-attribute("projectName"),

 

"projectId": fme:get-attribute("projectId"),

 

"projectDescription": fme:get-attribute("projectDescription"),

 

"projectDate": fme:get-attribute("projectDate"),

 

"propertyAddresses":d

 

fme:process-features("SUB")

 

],

 

"programType": fme:get-attribute("programType"),

 

"numberOfUnits": xs:double(fme:get-attribute("numberOfUnits")),

 

"numberOfSqFt": xs:double(fme:get-attribute("numberOfSqFt")),

 

"numberOfParkingSpaces": xs:double(fme:get-attribute("numberOfParkingSpaces")),

 

"numberOfHotelRooms": xs:double(fme:get-attribute("numberOfHotelRooms")),

 

"neighborhood": fme:get-attribute("neighborhood"),

 

"jobsRetained": xs:double(fme:get-attribute("jobsRetained")),

 

"jobsCreated": xs:double(fme:get-attribute("jobsCreated")),

 

"developer": fme:get-attribute("developer"),

 

"category": fme:get-attribute("category"),

 

"cagisId": fme:get-attribute("cagisId"),

 

"address": fme:get-attribute("address")

 

 

}

 


@takashi - I had a NullAttributeMapper in there before the JSONTemplater but had all values checked (empty, missing, and null). I just made the adjustment you suggested and received these errors:

 

JSONTemplater(XMLTemplaterFactory): The following error occurred near line 5, column 35 of the query:

JSONTemplater(XMLTemplaterFactory): "xs:string": invalid value for cast/constructor: can not cast to "xs:double"

JSONTemplater(XMLTemplaterFactory): A fatal error has occurred. Check the logfile above for details

 

Here's what's in the JSONTemplater:

 

{

 

"totalInvestment": xs:double(fme:get-attribute("totalInvestment")),

 

"squareFootageRetail": xs:double(fme:get-attribute("squareFootageRetail")),

 

"squareFootageOffice": xs:double(fme:get-attribute("squareFootageOffice")),

 

"squareFootageManufacturing": xs:double(fme:get-attribute("squareFootageManufacturing")),

 

"recordType": fme:get-attribute("recordType"),

 

"projectStage": fme:get-attribute("projectStage"),

 

"projectName": fme:get-attribute("projectName"),

 

"projectId": fme:get-attribute("projectId"),

 

"projectDescription": fme:get-attribute("projectDescription"),

 

"projectDate": fme:get-attribute("projectDate"),

 

"propertyAddresses":d

 

fme:process-features("SUB")

 

],

 

"programType": fme:get-attribute("programType"),

 

"numberOfUnits": xs:double(fme:get-attribute("numberOfUnits")),

 

"numberOfSqFt": xs:double(fme:get-attribute("numberOfSqFt")),

 

"numberOfParkingSpaces": xs:double(fme:get-attribute("numberOfParkingSpaces")),

 

"numberOfHotelRooms": xs:double(fme:get-attribute("numberOfHotelRooms")),

 

"neighborhood": fme:get-attribute("neighborhood"),

 

"jobsRetained": xs:double(fme:get-attribute("jobsRetained")),

 

"jobsCreated": xs:double(fme:get-attribute("jobsCreated")),

 

"developer": fme:get-attribute("developer"),

 

"category": fme:get-attribute("category"),

 

"cagisId": fme:get-attribute("cagisId"),

 

"address": fme:get-attribute("address")

 

 

}

 

Make sure that you have changed <null> and <empty> to <missing> with the NullAttributeMapper.

However, if the attribute stored a character string not representing a numeric value, the error would still appear since the NullAttributeValueMapper doesn't remove that. Please check what value is stored using the Logger or the Inspector.


Thanks. I attempted to convert one of my attributes to an integer in an attributemanager and neglected to back that out. That did the trick. Thanks!


Reply