How to where to store JSON files to access JSON as it is in UI(Headless arch) | Community
Skip to main content
Umamaheswari_Yakkala
New Participant
Jun 6, 2018 4:50 AM UTC
Solved

How to where to store JSON files to access JSON as it is in UI(Headless arch)

Hi Team,

We have a situation where we need to store the .JSON files as it is in same path and UI application is going to access this file. This is headless architecture.

What is the best place to keep this and that place should be accessible to team members and they can be able to upload it to the AEM like assets.

Any suggestions or ideas on this?

Thanks

Uma

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
kautuk_sahni
kautuk_sahniAccepted solution
Employee
Jun 6, 2018 3:03 PM UTC

Write a custom AEM service and then use JCR API to update the nodes.

Parse the values from JSON and then use API to update the nodes in the JCR -- for example:

//Store content from the client JSP in the JCR

   Node custNode = customerRoot.addNode("customer"+firstName+lastName+custId,"nt:unstructured");

              

  //make sure name of node is unique

  custNode.setProperty("id", custId);

  custNode.setProperty("firstName", firstName);

  custNode.setProperty("lastName", lastName);

See: Adobe Experience Manager Help | Persisting Adobe Experience Manager data in the Java Content Repository and Adobe Experience Manager Help | Submitting Adobe Experience Manager form data to Java Sling Servlets

If the Json data is huge then There are many libraries for serializing/deserializing JSON in java, the most notable is Google’s Gson: https://github.com/google/gson

Kautuk Sahni

9 replies

New Participant
Nov 19, 2018 9:27 AM UTC

This could be because of the dispatcher configs allow  ".json"  extention to be accessible

Translate
Umamaheswari_Yakkala
New Participant
Jun 7, 2018 5:29 PM UTC

I tried same way, somehow it didnt work for me, Let me try again. Thanks

Translate
joerghoh
Employee
Jun 6, 2018 9:52 PM UTC

Hi,

  • I have a file called tree.json on my local drive
  • I open my AEM 6.4 instance and browse into assets, /content/dam/we-retail
  • I drag and drop the tree.json into the browser window, triggering the upload it
  • tree.json is now being displayed as asset
  • I hit localhost:4502/content/dam/we-retail/tree.json
  • It is downloading the JSON file and it can be displayed correctly.

I did not have any problems with that approach.

Jörg

Translate
bhansa
Level 2
Jan 11, 2020 11:19 AM UTC

I also faced the same scenario where the file is getting downloaded, which means it is accessible. Is there any way that we can open the file in browser instead of downloading.

I am not trying to do it through DAM, instead I am trying to do that via codebase.

Translate
Umamaheswari_Yakkala
New Participant
Jun 6, 2018 7:55 PM UTC

Hi Jorg,

we are looking for that kind of option, where the team can go ahead and upload the JSON file and should be able to accessible in UI, I have uploaded and not able to read JSON from the publishers .. returning page not found.  This approach is working for txt and js but not JSON.

Is there any way that i can upload JSON into dam and can be able to read content of the file by accessing the URL ?

Thanks

Uma

Translate
joerghoh
Employee
Jun 6, 2018 7:06 PM UTC

Why don't you upload the JSON file as asset (just as you would upload images) and deliver it as is?

Jörg

Translate
kautuk_sahni
kautuk_sahniAccepted solution
Employee
Jun 6, 2018 3:03 PM UTC

Write a custom AEM service and then use JCR API to update the nodes.

Parse the values from JSON and then use API to update the nodes in the JCR -- for example:

//Store content from the client JSP in the JCR

   Node custNode = customerRoot.addNode("customer"+firstName+lastName+custId,"nt:unstructured");

              

  //make sure name of node is unique

  custNode.setProperty("id", custId);

  custNode.setProperty("firstName", firstName);

  custNode.setProperty("lastName", lastName);

See: Adobe Experience Manager Help | Persisting Adobe Experience Manager data in the Java Content Repository and Adobe Experience Manager Help | Submitting Adobe Experience Manager form data to Java Sling Servlets

If the Json data is huge then There are many libraries for serializing/deserializing JSON in java, the most notable is Google’s Gson: https://github.com/google/gson

Translate
Kautuk Sahni