Solved

JSON Validation Issue - Brackets, Braces, Commas (CONFUSED!!!)

  • 19 November 2018
  • 14 replies
  • 30 views

Badge

Hello:

I have an issue that I can't seem to understand. I'm new to JSON (in fact this is the first json output I've ever created). I have a structure that has a ROOT and SUB. The JSONTemplater says my current structure is valid and produces the file. However, when I run it through https://jsonlint.com/ the results are invalid. So, I looked at the output of what another area is expecting and I manually modified the file to see if the updates I made were valid. The short of it is, I need to modify what's in my JSONTemplater to add a comma (,) before each NEW record and add brackets ([ ]) around the entire output file. EVERY attempt I've made in modify the JSONTemplater has failed or I get an error. I'm loosing it! :) I've attached the file I manually revised and the one from the actual results of the workspace.

 

Can someone tell me what's wrong with my JSONTemplater?

 

ROOT Structure:

{

 

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

 

[

 

{ 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")

 

}

 

SUB Structure:

{

 

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

 

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

 

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

 

}
icon

Best answer by david_r 19 November 2018, 15:03

View original

14 replies

Badge
Hello - I may have confused you @david_r. The result is one (1) json file. The two (2) files was the actual results from the current ROOT and SUB you see in the post (brandon_revised.json). The other file (brandon_revised_manual.json) is what I need the file to look like from the JSONTemplater with whatever adjustments I need to make to the ROOT and/or SUB. Does that make sense?
Userlevel 4
Hello - I may have confused you @david_r. The result is one (1) json file. The two (2) files was the actual results from the current ROOT and SUB you see in the post (brandon_revised.json). The other file (brandon_revised_manual.json) is what I need the file to look like from the JSONTemplater with whatever adjustments I need to make to the ROOT and/or SUB. Does that make sense?

Sure, that's how I understood it :-)

Did you try the setup that I suggested?

Badge

Also @david_r - the images you provided are blank. If you can re-post them that would be great.

Userlevel 4

Yeah, sorry about the images, the forum has been weird after the updates, not sure why it's not working. Let's try again

Badge

@david_r - I loaded the workspace DCED_MOMENTUM_MAP_FOR_CAGIS.fmw Will this help?

Userlevel 4

@david_r - I loaded the workspace DCED_MOMENTUM_MAP_FOR_CAGIS.fmw Will this help?

Thanks! I see that you have a Sampler in your workspace so that you only ever get a single ROOT block in out JSON document. As a result, the output JSON is valid.

But in "brandon-revised.json" you have multiple ROOT blocks, which is what's invalidating the JSON. How is that possible? Did you not use the Sampler (in the same way) when that document was generated?

Badge

Thanks! I see that you have a Sampler in your workspace so that you only ever get a single ROOT block in out JSON document. As a result, the output JSON is valid.

But in "brandon-revised.json" you have multiple ROOT blocks, which is what's invalidating the JSON. How is that possible? Did you not use the Sampler (in the same way) when that document was generated?

@david_r - I added the sampler per another issue I had that @takashi helped me with. When I take the output of brandon_revised.json and evalute it on the website I mentioned, it fails. I apologize if I'm making things more confusing. The Sampler was added because of duplicate project names in the resulting SQL. Each record differed based on the ADDRESS (a project could have multiple addresses/parcels so we want to have 1 root and multiple subs as necessary). Again, I'm a newbie to JSON so if there is a better way to get the results from the current workspace I provided to look like the manually updated brandon_revised_manual.json file I'm all ears.

Userlevel 4

I'm assuming the main object here is some sort of property project, where each project has several addresses, and that each project is uniquely identified by the "projectId" attribute. Correct me if I'm wrong.

  • You need a single ROOT block to encapsulate the list of all the project objects
  • You need one MAIN block for each project
  • You need one or several SUB blocks for each address associated with a project. To avoid all addresses being listed for every project, you need to specify the primary/foreign key relationship between the project and the addresses. I'm going to assume this is also done through the "projectId" attribute. This is done when calling the SUB template (see also the JSONTemplater docs):
{ fme:process-features("SUB", "projectId", fme:get-attribute("projectId")) }

Based on my assumptions, I've tried to modify the workspace accordingly, see attached. Since I do not have access to the input data I haven't been able to test it, but I think the concept should hold, if not, let me know.

22978-dced-momentum-map-for-cagis.fmw

Badge

I'm assuming the main object here is some sort of property project, where each project has several addresses, and that each project is uniquely identified by the "projectId" attribute. Correct me if I'm wrong.

  • You need a single ROOT block to encapsulate the list of all the project objects
  • You need one MAIN block for each project
  • You need one or several SUB blocks for each address associated with a project. To avoid all addresses being listed for every project, you need to specify the primary/foreign key relationship between the project and the addresses. I'm going to assume this is also done through the "projectId" attribute. This is done when calling the SUB template (see also the JSONTemplater docs):
{ fme:process-features("SUB", "projectId", fme:get-attribute("projectId")) }

Based on my assumptions, I've tried to modify the workspace accordingly, see attached. Since I do not have access to the input data I haven't been able to test it, but I think the concept should hold, if not, let me know.

22978-dced-momentum-map-for-cagis.fmw

Thanks @david_r.  Your assumptions are correct. The structure you provided makes sense now. I made the changes and the output consisted of only [] in the results?

0684Q00000ArMSmQAN.png

Badge

I'm assuming the main object here is some sort of property project, where each project has several addresses, and that each project is uniquely identified by the "projectId" attribute. Correct me if I'm wrong.

  • You need a single ROOT block to encapsulate the list of all the project objects
  • You need one MAIN block for each project
  • You need one or several SUB blocks for each address associated with a project. To avoid all addresses being listed for every project, you need to specify the primary/foreign key relationship between the project and the addresses. I'm going to assume this is also done through the "projectId" attribute. This is done when calling the SUB template (see also the JSONTemplater docs):
{ fme:process-features("SUB", "projectId", fme:get-attribute("projectId")) }

Based on my assumptions, I've tried to modify the workspace accordingly, see attached. Since I do not have access to the input data I haven't been able to test it, but I think the concept should hold, if not, let me know.

22978-dced-momentum-map-for-cagis.fmw

@david_r - any thoughts on why the output would only contain [ ] ? I've tried a number of variations but It's almost as if MAIN is the only contents that is considered? 

Userlevel 4

@david_r - any thoughts on why the output would only contain [ ] ? I've tried a number of variations but It's almost as if MAIN is the only contents that is considered?

It's almost impossible to say without seeing the features that enter the JSONTemplater.

If you're allowed to post the data, you can insert a Recorder transformer on each of the JSONTemplater inputs and post the resulting ffs files here.

Badge

It's almost impossible to say without seeing the features that enter the JSONTemplater.

If you're allowed to post the data, you can insert a Recorder transformer on each of the JSONTemplater inputs and post the resulting ffs files here.

Here's the file - for_david_r.zip

This is from my original workspace with the Sampler (as opposed to the duplicator). Since I couldn't get either approach to work, I figured this output would suffice as well?

Userlevel 4

Here's the file - for_david_r.zip

This is from my original workspace with the Sampler (as opposed to the duplicator). Since I couldn't get either approach to work, I figured this output would suffice as well?

Thanks! Try removing the "Group Sub-Features By" clause in the JSONTemplater. You don't need it since the MAIN template now explicitely asks for the SUB features based on the matching "projectId" value.

I'm not sure if it's by design, but you do get some duplicate addresses. If that's not what you wanted, you can use another DuplicateFilter on the combination "projectId" and "address" (or whatever makes sense to you) on the input to the SUB template:

I've attached the output I got based on your ffs input.

output.json

Badge

Thanks! Try removing the "Group Sub-Features By" clause in the JSONTemplater. You don't need it since the MAIN template now explicitely asks for the SUB features based on the matching "projectId" value.

I'm not sure if it's by design, but you do get some duplicate addresses. If that's not what you wanted, you can use another DuplicateFilter on the combination "projectId" and "address" (or whatever makes sense to you) on the input to the SUB template:

I've attached the output I got based on your ffs input.

output.json

Thank you very much @david_r.

Reply