Jump to content

A Non-Strict JSON UDF (JSMN)


Ward
 Share

Recommended Posts

@Ward

@Jos

 

Hi

As a feedback for both of you: On Nexus Mods I use in my program "QMod SAM" your JSON UDF and have there in the tab "description" a link to this topic set here.

So also at this point: Thanks for this UDF!

QMod SAM (see "Special Thanks:")

P.S.: Jos, are your recent changes stable so far that I can take over your latest version? Currently I am using the official version of the startup post.

Edited by LukeWCS
Link to comment
Share on other sites

Response={"value":null}
Response={"value":""}
Response={"value":[]}
Response={"value":{}}
Response={"value":True}
Response={"value":1000}
Response={"value":["TX0058_2","TX0058_5"]}
Response={"value":{"TX0058_2":"A","TX0058_5":"D"]}

As shown above.

If the value 'Response' I get may be one of the above results,

 I want to further resolve the value of '[value]',

what functions or methods can I use to distinguish them?

Edited by Letraindusoir
Link to comment
Share on other sites

  • Developers
2 hours ago, LukeWCS said:

P.S.: Jos, are your recent changes stable so far that I can take over your latest version? Currently I am using the official version of the startup post.

Aren't they the same?  see the dates are. 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
19 minutes ago, Letraindusoir said:

what functions or methods can I use to distinguish them?

No idea what the question is and the posted code isn't Autoit so please post something that is autoIt3 and supports your question. :) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

51 minutes ago, Jos said:

Aren't they the same?  see the dates are. 

Jos

 

Yes, the dates are the same, but the json.au3 files are definitely different. I mean that post from you:

 

 

This is not the same json.au3 as the one from the first post.

Edited by LukeWCS
Link to comment
Share on other sites

  • Developers

mmm.... guess I forgot about that.
Updated the first post with this change assuming it is working correctly as I haven't heard differently. :)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
21 minutes ago, LukeWCS said:

@Jos

Hmm.. but _Json(2019.07.15).zip is exactly the same as _Json(2019.01.17).zip. ^^

Yea, you are right, I took it from the wrong place. 
I've cleaned up the commented old lines a bit and also changed the header version data.
Hope it is now the correct/complete version, but the posted testscript is working nicely with this one.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

In current (_Json(2019.07.15)b.zip)  JSON_Test.au3:

@Jos

Test5() has an undeclared variable on Line #79:

 

Test6 failed.  Not sure if that was intended or not.

> ========= Test6 Start   =========================
+-> .d.5.4.6.h[0].id  =1286
+-> .d.5.4.6.h[0].status  =sunny
+-> .d.5.4.6.h[0].earth  =True
+@@ Json_ObjExists($oTemp, "d") = True
!!!!@@ Json_ObjExists($oTemp, "d.5") = False
!!!!@@ Json_ObjExists($oTemp, "d.5.4") = False
!!!!@@ Json_ObjExists($oTemp, "d.5.4.6") = False
!!!!@@ Json_ObjExists($oTemp, "d.5.4.6.h") = False
+@@ Json_ObjExists($oTemp, "d.5.4.6.x") = False
!!!!@@ Json_Get($oTemp, "[0].id") = 
+@@ Json_Get($oTemp, "[0].id") = 
! ========= Test6 Failed! =========================

 

Edited by TheXman
Link to comment
Share on other sites

2 hours ago, Jos said:

I've cleaned up the commented old lines a bit and also changed the header version data.
Hope it is now the correct/complete version, but the posted testscript is working nicely with this one.

Okay, then I will update now and test my program with the new JSON UDF version.

Thanks again Jos. :)

Edited by LukeWCS
Link to comment
Share on other sites

  • Developers
11 hours ago, TheXman said:

Test5() has an undeclared variable on Line #79:

 

Test6 failed.  Not sure if that was intended or not.

mmm...   let me check what is happening ....  guess it has been too long ago I use all of this JSON stuff. :) 

10 hours ago, LukeWCS said:

Okay, then I will update now and test my program with the new JSON UDF version.

Please wait till things are checked!
Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
4 hours ago, LukeWCS said:

BTW, I did several tests and found no problems. All .json files are fine. I keep testing.

Understand as the issue is just with test 6 ( test 5 is fixed), which is an change I made a while ago to support  sub-objects in Json_ObjExists() and ObjGet().
This is not that commonly used.

Just some lack of time at the moment so reverted until that is fixed in the new version.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi together,

 

I am quite new here and wanted to try out a Webdriver Demo. In that Demo the author is using JSON.au3, but I get a compile error.

And wherever I have searched I don't find the right JSON.au3 or any JSMN.au3, which I can use.

At the beginning of that topic Ward's mentioning, "..I use a machine code version of JSON parser called jsmn.."

 

Hot to deal with it. I am lost with my first step.

Can anybody see me down there, if so, any help is much appreciated.

Link to comment
Share on other sites

Hi Dan, thx for quick answer.

When I click the link of Gabi, there is a self refernce to the same page.

Can you tell me what I am doing wrong or give me a link for not talented? 

 

 

 

 

Hi together,

 

I am quite new here and wanted to try out a Webdriver Demo. In that Demo the author is using JSON.au3, but I get a compile error.

And wherever I have searched I don't find the right JSON.au3 or any JSMN.au3, which I can use.

At the beginning of that topic there is a 

Link to comment
Share on other sites

Yepp

works, thank you very much :)

 

Hi together,

 

I am quite new here and wanted to try out a Webdriver Demo. In that Demo the author is using JSON.au3, but I get a compile error.

And wherever I have searched I don't find the right JSON.au3 or any JSMN.au3, which I can use.

At the beginning of that topic there is a 

Link to comment
Share on other sites

Update: I reverted to the earlier json.au3 file (01-08-2015) and the code worked fine.   I can't figure out why the code change to the json_get function in the 2019 version caused the error I'm getting but since it's a work in progress, my bad for not waiting for a more "official" release.

Hello All:

I'm trying to read a json file created by a website API.  Initially all I've tried to do is read a couple of the values but haven't been able to get past that step.

I'm using the json_get function from Json.au3 but keep receiving an @error = 1 that indicates it's a "no specific object" error.  I've used code from this site that doesn't appear to require the calling function set a variable as an object before calling the json_get function. 

In the examples I've seen and I've used below, it seems that the code $object = Json_Decode($data) is sufficient but I have not been able to get that to work.  I've tried setting the variable $object = Json_ObjectCreate() before setting $object = Json_Decode($data) but that has not worked either.

I've looked at the Json.au3 code and read as much as I can on the site that relates to what I'm trying to do but haven't found anything that works. 

I've included a test.json file and the first 3 records from the json.dump to show what the structure looks like.

I'm just starting to try to figure out JSON and the Json.au3 functions so any help would be appreciated.

-Bill

Note: uncomment the #include <json.au3> line in the code below.  If you don't need to see the full dump file you should comment out or remove the json_dump($data) line of code.

Func _JsonTest()
    ;#include <json.au3> ; Using the 01-17-2019 version
    Local $data
    Local $id
    Local $sTestJSonPath = @ScriptDir & "\test.json"
    Local $iFileSize = 0
    Global $object

    Local $hOpenFile = FileOpen($sTestJSonPath)
    If @error Then
        ConsoleWrite("@error = " & @error & @CRLF & "Could not open " & $sTestJSonPath & @CRLF)
    EndIf

    $iFileSize = FileGetSize($sTestJSonPath)

    $data = FileRead($hOpenFile)
    FileClose($hOpenFile)

    ; Dump the json file contents
    json_dump($data)

    $object = Json_Decode($data)

    Local $i = 0
    While 1
        ConsoleWrite("$i = " & $i & @CRLF)
        $id = json_Get($object, "[" & $i & "].id")
        ; Get an @error = 1, which I believe is the "no specific object" error in json_get

        If @error Then
            ConsoleWrite("@error = " & @error & @CRLF)
            ExitLoop
        EndIf
        ConsoleWrite('id:' & $id & @CRLF)
        $i += 1
    WEnd
EndFunc   ;==>_JsonTest

 

test.json Dump.text

Edited by OldGuyWalking
Reverted to earlier json.au3 and problem solved.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...