Jump to content

Recommended Posts

Posted (edited)

Give me few hours.
I will test with my WD related projects.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 11/18/2021 at 6:35 PM, mLipok said:

Give me few hours.
I will test with my WD related projects.

Expand  

Works well on 2 advanced WD automation also with my capabilities UDF.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
Posted (edited)

For anyone who may need it and in response to the above post, I have attached a modified version of the latest UDF that adds 3 new "helper" functions:

  1. Json_ArrayAdd(ByRef $Var, $Notation, $Data)
    Adds an item (String, number, object, array, or boolean) to an existing array.
  2. Json_ArrayInsert(ByRef $Var, $Notation, $Index, $Data)
    Inserts an array item (String, number, object, array, or boolean) at the specified index.
  3. Json_ArrayDelete(ByRef $Var, $Notation, $Range)
    Deletes a single item, a range of items, or multiple items, from an existing array.  The syntax for $Range is the same as _ArrayDelete() since that is what it uses to delete array items.

Note:  Json_ArrayAdd() and Json_ArrayInsert() only allow adding or inserting a single array item (String, number, object, array, or boolean) at a time.

Below are some examples using the functions and the output that's generated

  Reveal hidden contents

Output:

  Reveal hidden contents

 

Json(with array funcs).au3Fetching info...

Edited by TheXman
  • 2 months later...
Posted (edited)

Please consider to add somehing like $__JSONVERSION and $__BinaryCall_VERSION then other UDF (for example WebDriver UDF) can check if they are recent and put the version to console on debuging runs.


This feature could prevent such issues:

https://github.com/Danp2/WebDriver/pull/173#issuecomment-1029042637

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 1 month later...
Posted

I have a problem with Json_ObjGetCount()

Here is my code:

#include "Json.au3"

test5()

Func test5()
    Local $_WD_CAPS__OBJECT
    Json_Put($_WD_CAPS__OBJECT, "[capabilities][firstMatch][0][proxy][noProxy][0]", 'www.google.com')
    Json_Put($_WD_CAPS__OBJECT, "[capabilities][firstMatch][0][proxy][noProxy][1]", 'www.yahoo.com')
    ConsoleWrite("Test #5 Result: " & Json_Encode($_WD_CAPS__OBJECT) & @LF)

    Local $oTemp

    $oTemp = Json_ObjGet($_WD_CAPS__OBJECT, 'capabilities.firstMatch[0]')
    ConsoleWrite("! " & @CRLF)

    ConsoleWrite("- " & Json_ObjGetCount($oTemp) & @CRLF)

    Local $noProxy = Json_ObjGet($_WD_CAPS__OBJECT, '[capabilities][firstMatch][0][proxy][noProxy]')
    ConsoleWrite("- " & Json_ObjGetCount($noProxy) & @CRLF)


EndFunc   ;==>test5

 

My question is:  How to get number of [noProxy] entries ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

uff.. 
Found this:
 

Local $noProxy = Json_Get($_WD_CAPS__OBJECT, '[capabilities][firstMatch][0][proxy][noProxy]')
    ConsoleWrite("! $noProxy = " & VarGetType($noProxy) & @CRLF)
    ConsoleWrite(UBound($noProxy) & @CRLF)

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Why?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Yes. But for my needs it is not necesary as I check it with UBound()
 

#include "Json.au3"

ConsoleWrite('> #' & test5() & @CRLF)

Func test5()
    Local $_WD_CAPS__OBJECT
    Json_Put($_WD_CAPS__OBJECT, "[capabilities][firstMatch][0][proxy][noProxy][0]", 'www.google.com')
    Json_Put($_WD_CAPS__OBJECT, "[capabilities][firstMatch][0][proxy][noProxy][1]", 'www.yahoo.com')
    ConsoleWrite("Test #5 Result: " & Json_Encode($_WD_CAPS__OBJECT) & @LF)
    Return UBound(Json_Get($_WD_CAPS__OBJECT, '[capabilities][firstMatch][0][proxy][noProxy]'))
EndFunc   ;==>test5

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 11/20/2021 at 8:32 PM, TheXman said:

For anyone who may need it and in response to the above post, I have attached a modified version of the latest UDF that adds 3 new "helper" functions:

Expand  

Hi

Saw today that there is an update on this UDF, thanks TheXman. :)

Tested with my mod manager, no problems found. 

 

Edited by LukeWCS
Posted

Sorry, I dont understand very well english, I am trying to use webdriver to automate Chrome, I download webdriver but I am keep receveing an error like "#include json.udf" I think it's due to lack of this library, but I cannot find where to get it, Can someone help me? Once I downloaded it I should insert it in the include directory in the autoit directory right?

Posted
  On 3/30/2022 at 12:05 PM, MarcoMonte said:

but I am keep receveing an error like "#include json.udf"

Expand  

The include statement should look like this :

#include "Json.au3"

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

  • 2 weeks later...
Posted (edited)

Does the Json_ObjExists() function should support brace-based notation?

I had some problem with this:

#include "Json.au3"

test5()

Func test5()
    Local $_WD_CAPS__OBJECT
    Json_Put($_WD_CAPS__OBJECT, "[capabilities][alwaysMatch]", '{}')
    Json_Put($_WD_CAPS__OBJECT, "[capabilities][firstMatch][0][proxy][noProxy][0]", 'www.google.com')
    Json_Put($_WD_CAPS__OBJECT, "[capabilities][firstMatch][0][proxy][noProxy][1]", 'www.yahoo.com')
    ConsoleWrite("Test #5 Result: " & Json_Encode($_WD_CAPS__OBJECT) & @LF)
    Local $v_Test

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, '[capabilities][firstMatch]')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, 'capabilities.firstMatch')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, '[capabilities][alwaysMatch]')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, 'capabilities.alwaysMatch')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

EndFunc   ;==>test5

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Using Json_ObjExists() I get err that variable must be object.

Should we check IsObj() like this:
 

Func Json_ObjExists(ByRef $Object, $Key)
    If Not IsObj($Object) Then Return False

?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Interesting reading about:  Primitive and compound JSON data types

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 4/8/2022 at 6:38 AM, mLipok said:

Using Json_ObjExists() I get err that variable must be object.

Expand  

 

here is my testing script:
 

#include "Json.au3"

test5()

Func test5()
    Local $_WD_CAPS__OBJECT
    Local $v_Test

    Json_Put($_WD_CAPS__OBJECT, '[capabilities]', '{}')
    ConsoleWrite("Test #5 Empty: " & Json_Encode($_WD_CAPS__OBJECT) & @LF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, 'capabilities')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, 'capabilities.alwaysMatch')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, 'capabilities.firstMatch')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)


    Json_Put($_WD_CAPS__OBJECT, "[capabilities][alwaysMatch]", '{}')
    Json_Put($_WD_CAPS__OBJECT, "[capabilities][firstMatch][0][proxy][noProxy][0]", 'www.google.com')
    Json_Put($_WD_CAPS__OBJECT, "[capabilities][firstMatch][0][proxy][noProxy][1]", 'www.yahoo.com')
    ConsoleWrite("Test #5 Result: " & Json_Encode($_WD_CAPS__OBJECT) & @LF)

    $v_Test = UBound(Json_Get($_WD_CAPS__OBJECT, '[capabilities][firstMatch][0][proxy][noProxy]'))
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

    $v_Test = UBound(Json_Get($_WD_CAPS__OBJECT, '[capabilities][firstMatch]'))
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, '[capabilities][firstMatch]')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, 'capabilities.firstMatch')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, '[capabilities][alwaysMatch]')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, 'capabilities.alwaysMatch')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

EndFunc   ;==>test5


I get this error:

"Z:\!!!_SVN_AU3\UDF_Forum\Other_Members\Official_AutoIt_Forum\JSON\Json.au3" (356) : ==> Variable must be of type "Object".:
If $DynObject.Exists($Keys[$x]) Then
If $DynObject^ ERROR

On this line:

Func Json_ObjExists(ByRef $Object, $Key)
    Local $DynObject = $Object
    Local $Keys = StringSplit($Key, ".")
    For $x = 1 To $Keys[0]
        If $DynObject.Exists($Keys[$x]) Then



Here is smaller reproducion script:
 

#include "Json.au3"

test5()

Func test5()
    Local $_WD_CAPS__OBJECT
    Local $v_Test

    Json_Put($_WD_CAPS__OBJECT, '[capabilities]', '{}')
    ConsoleWrite("Test #5 Empty: " & Json_Encode($_WD_CAPS__OBJECT) & @LF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, 'capabilities')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

    $v_Test = Json_ObjExists($_WD_CAPS__OBJECT, 'capabilities.alwaysMatch')
    ConsoleWrite("- " & @ScriptLineNumber &  ' $v_Test = ' & $v_Test  & @CRLF)

EndFunc   ;==>test5

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

@mLipok try with this Json_ObjExists modification

Func Json_ObjExists(ByRef $Object, $Key)
    Local $DynObject = $Object
    Local $Keys = StringSplit($Key, ".")
    For $x = 1 To $Keys[0]
        If $DynObject.Exists($Keys[$x]) Then
            If $x = $Keys[0] Then
                Return True
            Else
                $DynObject = Json_ObjGet($DynObject, $Keys[$x])
                If Not IsObj($DynObject) Then Return False      ;~~~~ add this line to Check if $DynObject is object
            EndIf
        Else
            Return False
        EndIf
    Next
    Return False
EndFunc   ;==>Json_ObjExists

 

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
×
×
  • Create New...