Read from local JSON File

Hello, I am currently trying to parse objects from a local JSON-File. I have already created the JSON-Structure and the Mapping that I need, but I can’t figure out how to access a local file from within a Microflow. I have downloaded the CommunityCommons Package from Marketplace, but can’t find specifics in the Documentation on how to use it. The StringFromFile activity should do what I need, but I do not understand what the System.FileDocument input needs me to do. I would be thankful for help here, I am still quite new to Mendix Best regards, Maruan El-Mahgary
3 answers

You’ll need to create an entity that has a generalisation from System.FileDocument in your domain model. In a microflow, create an instance of this entity and pass it into GetFileContentsFromResource (in Community Commons) along with the name of the local file you want to read in. This file needs to be in your application’s resources directory. You then pass the entity you created into StringFromFile (in CommunityCommons), which will return the contents of the file in a String.

So for example, if I want to load up a file called text.txt and show it, I can do the following.

Hope this helps. 


Rather than trying to make your microflow read a local file, you can do follow the following:

  • Develop an file upload functionality, so you can upload the JSON file to your application
  • Use StringFromFile from community commons to get the string from the filedocument
  • Then use the content, parse


Another solution, you could also:

  • Copy paste the contents of the JSON to a String attribute in entity 
  • Parse the string


Or, develop REST POST service and send the content of JSON via the REST service.


Thanks to both of you for your advice.
I picked the solution of running a Rest Post service locally on my machine since consuming a REST Call is closer to what I actually need for my project in the end.
I currently only need to test some of my code and thought a JSON would be easier to fetch locally from my machine instead of from a REST Service, but it seems I was wrong there. Learned something new about Mendix!