Simple neoapp to create, export and import a json file. - Forum

Forum Navigation
You need to log in to create posts and topics.

Simple neoapp to create, export and import a json file.

Hello all,
I am testing out Visual Neo Web and considering purchasing it, and have a little experience from years ago with Neobook Pro.

I am still in a learning phase but have tried for about two hours today to do something that takes me about two minutes with html + JS.
It actually started out to pulling .json from a api and parsing it, but never could get that to work right.
I ended up creating a simple file with 4 text input fields and two buttons.

The idea was to have a name field and a age field, enter the details, click a button and save a user.json file locally.  That went ok.
The second button would then load the user.json file parse it to two variables and fill in the two additional text fields.

I have looked through some of the sample files with Visual Neo Web ( specifically the ones one json ), but still this simple task alludes me.

Can someone explain how to simply load and parse a .json file properly or create a simple demo file for me to explore and see how it is accomplished.

Thank you.

 

Hi @tom0360,

Please, check the attached sample app.
Let me know if you have any questions.

Regards.

Luis.

Uploaded files:
  • You need to login to have access to uploads.
tom0360 has reacted to this post.
tom0360

Thank you Luis.

This looks much better than my Frankenstein approach...

I finally got it working but figured it was probably not the best way. I just mixed a bunch of things I seen in the sample files together until something worked. lol
This was the mess I was using.

neoFileOpenBox "documents" "text/plain" "" "Text File" "getFileHandle"
SetVar [contents] [data]

ParseJSON "[contents]" [myjson]
SetVar [userName] [myjson('name')]
SetVar [userAge] [myjson('age')]

Subroutines:

:getFileHandle
SetVar [fileHandle] [data]
Consolelog [fileHandle]
.Get some file information
neoFileName [fileHandle] "getFileName"
neoFileSize [fileHandle] "getFileSize"
.Load the file content
neoFileRead [fileHandle] "loadContent"

:loadContent
SetVar [contents] [data]

I think I was getting closer but was still unsure what was the correct method.

@tom0360 It seems you decided to use neoFileSystem plugin.
It allows better control when you need to write content into an existing file but it only works on Chromium based web browsers, after user permission and under a "secure context".
If you just need to load and download files it's quite better and simple my approach.
Note that you can also store and retrieve local data using Local Storage instead of traditional files (as they have much more security restrictions).

Regards.

 

tom0360 has reacted to this post.
tom0360

Thank you Luis.

What you shared helps to make sense a little more of what I was missing.

One quick question, using this same method, would adding a checkbox work in the same way?
For some reason when saving a checkboxes state true/false to the json file, it saves fine but on loading it back in, it does not automatically check the box if it was set to true. I know in JavaScript there is additional code needed to check and set options boxes when saving and loading to json.
I am thinking perhaps I need to add a bit more in VisualNeo as well.

Thank you.

@tom0360 yes it works the same.
Please check attached updated sample app.

Uploaded files:
  • You need to login to have access to uploads.

Thank you again.

I could not get the save to work right using your example, but this did work:

SetVar [saveJSON] '{"name": "[userName]", "age": "[userAge]", "option1": [optVar1]}'
VarToLocalFile [saveJSON] "[userName].json"

I originally was wrapping the checkbox state in " " like "option1": "[optVar1]" }, which I am guessing made it consider it a string and when loading it expected a Boolean.

I will play around with the saving as I can see if there was a lot of data to save, my way will be a real mess to keep straight.

Edited: Save is now working from you example.