Valid JSON file ?

If I can read a JSON file, may I assume that that JSON file is valid ?

[code]Dim OpenTIS As TextInputStream
Dim MyJason As New JSONItem

// Skipped code

MyJason.Constructor(OpenTIS.ReadAll)

TA.Text = MyJason.ToString[/code]

TA is a TextArea.

I would say so.

But why not using the new dictionary instead
Using the xojo.core.dictionary object, and the classes with xojo.data… to generate and parse the Json data…

Thank you Edwin for your kind anwser and advice :wink:

Because I use Xojo 2015r1 to build the application and I get consistent errors trying to do that.

I will use these in the future when I will upgrade Xojo.

I may also get an eye on that while booting on Sierra from an external HD. The errors may not be because of Xojo 2015r1.

[quote=298311:@Emile Schwarz]Thank you Edwin for your kind anwser and advice :wink:

Because I use Xojo 2015r1 to build the application and I get consistent errors trying to do that.

I will use these in the future when I will upgrade Xojo.

I may also get an eye on that while booting on Sierra from an external HD. The errors may not be because of Xojo 2015r1.[/quote]

Weird… I never had problems. Just make sure you have the newest Xojo version. I don’t know why the OS would make a difference. But you can always try

[quote=298295:@Emile Schwarz]If I can read a JSON file, may I assume that that JSON file is valid ?

[code]Dim OpenTIS As TextInputStream
Dim MyJason As New JSONItem

// Skipped code

MyJason.Constructor(OpenTIS.ReadAll)

TA.Text = MyJason.ToString[/code]

TA is a TextArea.[/quote]
Keep in mind that what’s going to happen if it’s not valid is a JSONException. You’ll need to wrap that code in a try-catch.

Thank you, I will try after lunch.

I just finished to try: works fine.

I made a second test with a json file from internet: it crashed (probably not an array json).

Also, I checked my own json file with MyJson.isArray and the answer is True.

Since last week, I’ve made some researches and found… books (with hundred pages) on the JSON subject, explanations and all of these mostly define JSON as a format to send / receive data from/to web page <—> web server, not as a real defined file as other files are used (like txt, pdf, doc, xls, gif, png, etc.).

I also found many software applciations that deals with text file format as converters: txt to csv, to xml, to JSON, pdf, etc.

Extremely strange: there is a real dichotomy between the perceived json and the real use of json files.

At last, I mostly found dictionary json vs nearly no array json files (except mine :wink: …). Unlike xml files who are rendered by browsers, I do not found an application that displays the json contents / a real human readable (with tabs / spaces / returns) application (browser) to display these (excepted those text converters applications) files.

In my projects where I implement JSON Export / Import, I added a test using MyJSONItem.isArray to reject what I do not use (Dictionary JSON). If asked (in the future), I can encapsulate my JSON Arrays to simulate a JSON Dictionary. However, I am totally unsure of the use (or useless) of JSON files in everyday life.

That is what the format was created for. I personally don’t like JSON as a storage format. But it is very pervasive as a transmission format. And as the web takes over as a paradigm, JSON will be unavoidable.

Why have you chosen JSON as a format? Have your users requested it? There’s no real reason to use it as a format unless your user is going to use it to transmit the data to an app that expects JSON (like a web site).

Marketing reasons ? Everyone want to do that ? Why not ? Nice icon in the ToolBar ? (space to fill in the ToolBar ?)
No web site use.

Yes, I know, a lot of not so good reasons. But, better add it before someone start to ask for it.

BTW: I already export as Tab / Return and CSV file format. The native format is .sqlite.