Jump to content

Json2


jugador
 Share

Recommended Posts

Searching how to access javascript
find few code by @genius257 & @Danyfirex
and this link https://www.autoitscript.com/forum/topic/156794-oo_jsonudf-jsonpath-oo-using-javascript-in-auto-it/

#include "Json2.au3"

;__Example_2()
;__Example_3()
__Example_4()
;__Example_5()
;__Example_6()
;__Example_7()

Func __Example_2()
    Local $Js_String = '{"name":"John","cars":{"A": "Ford","B": "BMW","C": "Fiat","D": "Chevy"}}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $0_Carsobj = $ParseJson.cars
    ConsoleWrite('1st item(A)-> ' & $0_Carsobj.item("A") & @Crlf)
    ConsoleWrite('1st item(B)-> ' & $0_Carsobj.item("B") & @Crlf)
    ConsoleWrite('1st item(C)-> ' & $0_Carsobj.C & @Crlf)
    ConsoleWrite('1st item(D)-> ' & $0_Carsobj.D & @Crlf)
EndFunc

Func __Example_3()
    Local $Js_String = '{"Company":"ABC","Model":[{"Car":"Ford","Color":"Red"},{"Car":"BMW","Color":"Blue"},' & _
                       '{"Car":"Fiat","Color":"Green"},{"Car":"Chevy","Color":"Black"}],"Price":0.00}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $Get_Model = $ParseJson.Model
    For $i = 0 To $Get_Model.length - 1
        ConsoleWrite($i & ': ' & $Get_Model.item($i).Car & @Tab)
        ConsoleWrite($Get_Model.item($i).Color & @CRLF)
    Next
EndFunc

Func __Example_4()
    Local $Js_String = '{"Company":"ABC","Data":[["A1",0.70],["B1",0.80],["C1",0.90],["D1",1.00]],"Plot":"No"}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $Get_Model = $ParseJson.Data
    Local $oData
    For $i = 0 To $Get_Model.length - 1
    $oData = $Get_Model.item($i)
        For $j = 0 To $oData.length - 1
            ConsoleWrite($oData.item($j) &  @Tab)
        Next
        ConsoleWrite(@CRLF)
    Next
EndFunc

Func __Example_5()
    Local $Js_String = '{"status":"OK","data":["156,195.75,265","157,295.95,365","158,395.95,465"]}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $Get_Data = $ParseJson.data
    For $i = 0 To $Get_Data.length - 1
        ConsoleWrite($Get_Data.item($i) & @Crlf)
    Next
EndFunc

Func __Example_6()
    Local $Js_String = '{"status":200,"payload":{"Name":"ABC","data":[[156,131,187],[157,132,188],[158,133,189]]}}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $Get_Data = $ParseJson.payload.data
    Local $oData
    For $i = 0 To $Get_Data.length - 1
    $oData = $Get_Data.item($i)
        For $j = 0 To $oData.length - 1
            ConsoleWrite($oData.item($j) &  @Tab)
        Next
        ConsoleWrite(@CRLF)
    Next
EndFunc

Func __Example_7()
    Local $Js_String = '{"status":"ok", "data":{ "Value":[["2019-04-04",712,146],["2019-04-05",713,147],["2019-04-06",714,148]]}}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $Get_Data = $ParseJson.data.Value
    Local $oData
    For $i = 0 To $Get_Data.length - 1
    $oData = $Get_Data.item($i)
        For $j = 0 To $oData.length - 1
            ConsoleWrite($oData.item($j) &  @Tab)
        Next
        ConsoleWrite(@CRLF)
    Next
EndFunc

 

important note:
https://www.autoitscript.com/forum/topic/206694-json2-parse/?do=findComment&comment=1497016

Version 1:  

Json2.au3

Version 2:

Json2.au3

Edited by jugador
Link to comment
Share on other sites

Json parse using ScriptControl Method is fast but consuming too much memory while parsing big json file.
and also not freeing memory even after parsing method is complete/done.

I didn't able to solve the (memory increasing)puzzle.
It will be great if someone have solution of this memory increasing problem of the above code.

besides as per stackoverflow.com search

Quote

ScriptControl-based approachs makes the system vulnerable in some cases,
since they allows a direct access to the drives (and other stuff) for the malicious JS code via ActiveX's.


So try to parse json using ObjCreate("htmlfile") and succeed :) .
speed almost same comparison to ScriptControl method
important part Memory usage normal.

Edited by jugador
Link to comment
Share on other sites

@Jos  when you run the above code(1st post).... memory not cooling off even after function is done.
is it Autoit ObjCreate or "ScriptControl" method or the code problem.

someone else also posted about ObjCreate("ScriptControl") problem
link ->  https://www.autoitscript.com/forum/topic/203446-5-lines-script-and-guidelete-crashes/

what's the reason.
Thanks.

Edited by jugador
Link to comment
Share on other sites

  • 4 months later...

No consuming of too much memory while parsing big json file using this udf..... :)

Memory usage bear minimum and it's super fast than any Json parse method on this forum till date.

To do this ...... use For in loop (not For to loop)

and to get rid of dot notation limitation you have to write your own prototype :P

after that no problem parsing this type of key value pair....

{"name":"John"}     ;~ ok
{"[name]":"John"}   ;~ ok
{"0name":"John"}    ;~ ok
{"0 name":"John"}   ;~ ok
{"0-name":"John"}   ;~ ok

That's it.

Edited by jugador
Link to comment
Share on other sites

> __GetElement
> __EditElement
> __DeleteElement

__Example_1A()
Func __Example_1A()
    Local $Js_String = '{"name":"John","cars-Name":[ "Ford", "BMW", "Fiat", "Chevy" ]}'

    Local $o_Obj = 0
    __JsonObjCreate($o_Obj)
    If @Error Then Return ConsoleWrite($o_Obj & @Crlf)

    Local $ParseJson = __JsonParse($o_Obj, $Js_String)
    If @Error Then Return ConsoleWrite($ParseJson & @Crlf)
    ConsoleWrite('# (Json stringify) => ' & @Crlf & __Json_PRETTY_PRINT($ParseJson, '', '') & @Crlf & @Crlf)

    ConsoleWrite('# (Get "cars-Name" key) => ' & @Crlf)
    Local $0_Carsobj = __GetElement($ParseJson, "cars-Name")
    ConsoleWrite('Cars Array length-> ' & $0_Carsobj.length & @Crlf)
    For $okey in $0_Carsobj
        ConsoleWrite($okey & @Crlf)
    Next
    ConsoleWrite(@Crlf)

    __EditElement($ParseJson, "name", "Steve")
    ConsoleWrite('# (Edit "name" from John to Steve) => ' & @Crlf & _
                    __Json_PRETTY_PRINT($ParseJson, '', '') & @Crlf & @Crlf)

    __EditElement($0_Carsobj, 1, "Toyota")
    ConsoleWrite('# (Edit "cars-Name" of BMW to Toyota) => ' & @Crlf & _
                    __Json_PRETTY_PRINT($ParseJson, '', '') & @Crlf & @Crlf)

    __DeleteElement($0_Carsobj, 0)
    ConsoleWrite('# (Delete Ford from "cars-Name" ) => ' & @Crlf & _
                    __Json_PRETTY_PRINT($ParseJson, '', '') & @Crlf & @Crlf)

    __DeleteElement($ParseJson, "name")
    ConsoleWrite('# (Delete "name" key) => ' & @Crlf & _
                    __Json_PRETTY_PRINT($ParseJson, '', '') & @Crlf & @Crlf)

    __DeleteElement($ParseJson, "cars-Name")
    ConsoleWrite('# (Delete "cars-Name" key) => ' & @Crlf & _
                    __Json_PRETTY_PRINT($ParseJson, '', '') & @Crlf & @Crlf)

    If IsObj($ParseJson) Then $ParseJson = 0    ;~ delete object
    If IsObj($o_Obj) Then $o_Obj = 0            ;~ delete object
EndFunc

 

Output:

# (Json stringify) => 
{"name":"John","cars-Name":["Ford","BMW","Fiat","Chevy"]}

# (Get "cars-Name" key) => 
Cars Array length-> 4
Ford
BMW
Fiat
Chevy

# (Edit "name" from John to Steve) => 
{"name":"Steve","cars-Name":["Ford","BMW","Fiat","Chevy"]}

# (Edit "cars-Name" of BMW to Toyota) => 
{"name":"Steve","cars-Name":["Ford","Toyota","Fiat","Chevy"]}

# (Delete Ford from "cars-Name" ) => 
{"name":"Steve","cars-Name":["Toyota","Fiat","Chevy"]}

# (Delete "name" key) => 
{"cars-Name":["Toyota","Fiat","Chevy"]}

# (Delete "cars-Name" key) => 
{}

 

Edited by jugador
Link to comment
Share on other sites

Example 1

> __InitiateNewObject
> __InitiateNewArray
> __AddElement

__Example_1B()

Func __Example_1B()
Local $o_Array[][] = [['GUICtrlMenuClick', 'https://www.autoitscript.com/forum/topic/205640-guictrlmenuclick/'], _
                      ['Array Reverse', 'https://www.autoitscript.com/forum/topic/206263-array-reverse/'], _
                      ['1D to 2D Array', 'https://www.autoitscript.com/forum/topic/206258-1d-to-2d-array/'], _
                      ['Array Column Delete', 'https://www.autoitscript.com/forum/topic/206244-array-column-delete/'], _
                      ['_ArrayColInsert', 'https://www.autoitscript.com/forum/topic/206264-_arraycolinsert/'], _
                      ['Json2', 'https://www.autoitscript.com/forum/topic/206694-json2-parse/']]

    Local $Js_String = '{}'

    Local $o_Obj = 0
    __JsonObjCreate($o_Obj)
    If @Error Then Return ConsoleWrite($o_Obj & @Crlf)

    Local $ParseJson = __JsonParse($o_Obj, $Js_String)
    If @Error Then Return ConsoleWrite($ParseJson & @Crlf)

    __AddElement($ParseJson, "Status", 200)

    Local $0_Object_Eg1 = __InitiateNewObject($ParseJson, "Software")
    __AddElement($0_Object_Eg1, 'S1', 'Javascript')
    __AddElement($0_Object_Eg1, 'S2', 'Autoit')

    Local $0_Array_Eg1 = __InitiateNewArray($ParseJson, "@jugador")
    Local $0_Array_Eg2 = __InitiateNewArray($ParseJson, "Link")

    Local $0_TempObject
    For $i = 0 To UBound($o_Array) - 1
        $0_TempObject = __InitiateNewObject($0_Array_Eg1, $i)
        __AddElement($0_TempObject, 'No', $i)
        __AddElement($0_TempObject, 'Eg_Scripts', $o_Array[$i][0])
    Next

    Local $0_TempArray
    For $i = 0 To UBound($o_Array) - 1
        $0_TempArray = __InitiateNewArray($0_Array_Eg2, $i)
        __AddElement($0_TempArray, 0, $i)
        __AddElement($0_TempArray, 1, $o_Array[$i][1])
    Next

    ConsoleWrite('# (Json object stringify) => ' & @Crlf & __Json_PRETTY_PRINT($ParseJson) & @Crlf & @Crlf)
    If IsObj($ParseJson) Then $ParseJson = 0    ;~ delete object
    If IsObj($o_Obj) Then $o_Obj = 0            ;~ delete object
EndFunc

Output:

# (Json object stringify) => 
{
    "Status": 200,
    "Software": {
        "S1": "Javascript",
        "S2": "Autoit"
    },
    "@jugador": [
        {
            "No": 0,
            "Eg_Scripts": "GUICtrlMenuClick"
        },
        {
            "No": 1,
            "Eg_Scripts": "Array Reverse"
        },
        {
            "No": 2,
            "Eg_Scripts": "1D to 2D Array"
        },
        {
            "No": 3,
            "Eg_Scripts": "Array Column Delete"
        },
        {
            "No": 4,
            "Eg_Scripts": "_ArrayColInsert"
        },
        {
            "No": 5,
            "Eg_Scripts": "Json2"
        }
    ],
    "Link": [
        [
            0,
            "https://www.autoitscript.com/forum/topic/205640-guictrlmenuclick/"
        ],
        [
            1,
            "https://www.autoitscript.com/forum/topic/206263-array-reverse/"
        ],
        [
            2,
            "https://www.autoitscript.com/forum/topic/206258-1d-to-2d-array/"
        ],
        [
            3,
            "https://www.autoitscript.com/forum/topic/206244-array-column-delete/"
        ],
        [
            4,
            "https://www.autoitscript.com/forum/topic/206264-_arraycolinsert/"
        ],
        [
            5,
            "https://www.autoitscript.com/forum/topic/206694-json2-parse/"
        ]
    ]
}

 

Example 2:

__Example_1C()

Func __Example_1C()
    ;~ Json sample link
    ;https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/?do=findComment&comment=1492518
    Local $Js_String = '{}'

    Local $o_Obj = 0
    __JsonObjCreate($o_Obj)
    If @Error Then Return ConsoleWrite($o_Obj & @Crlf)

    Local $ParseJson = __JsonParse($o_Obj, $Js_String)
    If @Error Then Return ConsoleWrite($ParseJson & @Crlf)

    __AddElement($ParseJson, 'description', "test json dataset")
    __AddElement($ParseJson, 'Forum', "Autoit")

    Local $0_TempObject
    Local $0_Array_Eg1 = __InitiateNewArray($ParseJson, "[[test]]")
    $0_TempObject = __InitiateNewObject($0_Array_Eg1, 0)
    __AddElement($0_TempObject, 'name', "test name 1")
    __AddElement($0_TempObject, 'number', 1)
    __AddElement($0_TempObject, 'boolean', True)
    __AddElement($0_TempObject, 'null_value', Null)

    $0_TempObject = __InitiateNewObject($0_Array_Eg1, 1)
    __AddElement($0_TempObject, 'name', "test name 2")
    __AddElement($0_TempObject, 'number', 2.5)
    __AddElement($0_TempObject, 'boolean', False)
    __AddElement($0_TempObject, 'null_value', Null)

    ConsoleWrite('# (Json stringify) => ' & @Crlf & __Json_PRETTY_PRINT($ParseJson) & @Crlf & @Crlf & @Crlf)

    Local $0_Testobj = __GetElement($ParseJson, "[[test]]")
    ConsoleWrite('# ("[[test]]" Array stringify) => ' & @Crlf & __Json_PRETTY_PRINT($0_Testobj, '', '') & @Crlf)

    If IsObj($ParseJson) Then $ParseJson = 0    ;~ delete object
    If IsObj($o_Obj) Then $o_Obj = 0            ;~ delete object
EndFunc

OutPut:

# (Json stringify) => 
{
    "description": "test json dataset",
    "Forum": "Autoit",
    "[[test]]": [
        {
            "name": "test name 1",
            "number": 1,
            "boolean": true,
            "null_value": null
        },
        {
            "name": "test name 2",
            "number": 2.5,
            "boolean": false,
            "null_value": null
        }
    ]
}


# ("[[test]]" Array stringify) => 
[{"name":"test name 1","number":1,"boolean":true,"null_value":null},{"name":"test name 2","number":2.5,"boolean":false,"null_value":null}]

 

Edited by jugador
Link to comment
Share on other sites

  • jugador changed the title to Json2
  • 4 weeks later...

While using Json2 if Json string contains backslash you will not get correct output
to solve this use StringReplace
for single backslash \ use ~
for double backslash \\ use \\\\

Edit: look like I miss updating version 2 of Json2 :sweating:

1st post updated.... :)

note:- if use version 2 of Json2 then to parse json you have to use For in loop.

Edited by jugador
Link to comment
Share on other sites

On google search saw someone ask to convert this csv to json
so for fun csv to json using Json2 UDF (need version 2 for this)

#include "Json2.au3"

__ExampleA()
Func __ExampleA()
    Local $o_CsvStr = 'album, year, US_peak_chart_post' & @CRLF & _
                      'The White Stripes, 1999, -' & @CRLF & _
                      'De Stijl, 2000, -' & @CRLF & _
                      'White Blood Cells, 2001, 61' & @CRLF & _
                      'Elephant, 2003, 6' & @CRLF & _
                      'Get Behind Me Satan, 2005, 3' & @CRLF & _
                      'Icky Thump, 2007, 2' & @CRLF & _
                      'Under Great White Northern Lights, 2010, 11' & @CRLF & _
                      'Live in Mississippi, 2011, -' & @CRLF & _
                      'Live at the Gold Dollar, 2012, -' & @CRLF & _
                      'Nine Miles from the White City, 2013, -'

__CSVtoJson($o_CsvStr)
;__CSVtoJson($o_CsvStr, ',', False)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: __CSVtoJson
; ===============================================================================================================================
Func __CSVtoJson($o_String, $o_delimiter = ',', $o_Key = True, $Js_String = '[]')
    Local $o_Line = StringSplit($o_String, @CR, 2)

    Local $o_Start = 1
    Local $o_GetKey = StringSplit($o_Line[0], $o_delimiter, 2)
    If Not $o_Key Then
        $o_Start = 0
        For $i = 0 To UBound($o_GetKey) - 1
            $o_GetKey[$i] = $i
        Next
    Endif

    Local $o_Obj = 0
    __JsonObjCreate($o_Obj)
    If @Error Then Return ConsoleWrite($o_Obj & @Crlf)

    Local $ParseJson = __JsonParse($o_Obj, $Js_String)
    If @Error Then Return ConsoleWrite($ParseJson & @Crlf)

    Local $o_TempObj
    Local $o_Text
    For $i = $o_Start To UBound($o_Line) - 1
        $o_Text = StringSplit($o_Line[$i], $o_delimiter, 2)
        $o_TempObj = ($o_Key ? __InitiateNewObject($ParseJson, $i - 1) : __InitiateNewArray($ParseJson, $i))
        For $k = 0 To UBound($o_GetKey) - 1
            __AddElement($o_TempObj, StringStripWS($o_GetKey[$k],1), StringStripWS($o_Text[$k],1))
        Next
    Next

    ConsoleWrite('# (Json object stringify) => ' & @Crlf & __Json_PRETTY_PRINT($ParseJson) & @Crlf & @Crlf)
    If IsObj($ParseJson) Then $ParseJson = 0
    If IsObj($o_Obj) Then $o_Obj = 0
EndFunc

 

# (Json object stringify) => 
[
    {
        "album": "The White Stripes",
        "year": "1999",
        "US_peak_chart_post": "-"
    },
    {
        "album": "De Stijl",
        "year": "2000",
        "US_peak_chart_post": "-"
    },
    {
        "album": "White Blood Cells",
        "year": "2001",
        "US_peak_chart_post": "61"
    },
    {
        "album": "Elephant",
        "year": "2003",
        "US_peak_chart_post": "6"
    },
    {
        "album": "Get Behind Me Satan",
        "year": "2005",
        "US_peak_chart_post": "3"
    },
    {
        "album": "Icky Thump",
        "year": "2007",
        "US_peak_chart_post": "2"
    },
    {
        "album": "Under Great White Northern Lights",
        "year": "2010",
        "US_peak_chart_post": "11"
    },
    {
        "album": "Live in Mississippi",
        "year": "2011",
        "US_peak_chart_post": "-"
    },
    {
        "album": "Live at the Gold Dollar",
        "year": "2012",
        "US_peak_chart_post": "-"
    },
    {
        "album": "Nine Miles from the White City",
        "year": "2013",
        "US_peak_chart_post": "-"
    }
]

 

Edited by jugador
Link to comment
Share on other sites

conversion of @mLipok example using Json2(Version 2) udf

#include <Array.au3>
#include "Json2.au3"

Opt("MustDeclareVars", 1)

__Example_1B()
Func __Example_1B()
    ;https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/?do=findComment&comment=1500000
    Local $Js_String = '{}'

    Local $o_Obj = 0
    __JsonObjCreate($o_Obj)
    If @Error Then Return ConsoleWrite($o_Obj & @Crlf)

    Local $ParseJson = __JsonParse($o_Obj, $Js_String)
    If @Error Then Return ConsoleWrite($ParseJson & @Crlf)

    ;~ fill key = Value
    Local $o_String = 'Primitive_'
    Local $o_Array[] = ['Test', True, False, Null]
    For $i = 0 To UBound($o_Array) - 1
        __AddElement($ParseJson, $o_String & ($i + 1), $o_Array[$i])
    Next

    ;~ initialize Array
    Local $o_KeyList[] = ['List_A', 'List_C', 'List_D']
    For $i = 0 To UBound($o_KeyList) - 1
        __InitiateNewArray($ParseJson, $o_KeyList[$i])
    Next
    __InitiateNewObject($ParseJson, 'Empty_object')

    Local $o_GetKey
    ;~~~~ fill List_A
    $o_GetKey = __GetElement($ParseJson, "List_A")
    For $i = 0 To UBound($o_Array) - 1
        __AddElement($o_GetKey, $i, $o_Array[$i])
    Next
    $o_GetKey = __InitiateNewObject($o_GetKey, 4)
    $o_GetKey = __InitiateNewObject($o_GetKey, "Object_1")
    $o_GetKey = __InitiateNewArray($o_GetKey, "List_A_B")
    For $i = 0 To UBound($o_Array) - 1
        __AddElement($o_GetKey, $i, $o_Array[$i])
    Next
    __AddElement($o_GetKey, UBound($o_Array), "value_A_B=100")

    ;~~~~ fill List_C
    $o_GetKey = __GetElement($ParseJson, "List_C")
    For $i = 0 To UBound($o_Array) - 1
        __AddElement($o_GetKey, $i, $o_Array[$i])
    Next
    __AddElement($o_GetKey, UBound($o_Array), "value_C=100")

    ;~~~~ fill List_D
    Local $o_ObjList[] = ['Object_2', 'Object_3']
    $o_GetKey = __GetElement($ParseJson, "List_D")
    $o_GetKey = __InitiateNewObject($o_GetKey, 0)
    For $i = 0 To UBound($o_ObjList) - 1
        __InitiateNewObject($o_GetKey, $o_ObjList[$i])
    Next

    Local $o_TmpKey
    ;~~~~ fill Object_2 of List_D object
    $o_TmpKey = __GetElement($o_GetKey, "Object_2")
    $o_TmpKey = __InitiateNewArray($o_TmpKey, "List_D_E")
    For $i = 0 To UBound($o_Array) - 1
        __AddElement($o_TmpKey, $i, $o_Array[$i])
    Next
    __AddElement($o_TmpKey, UBound($o_Array), "value_D_E=100")

    ;~~~~ fill Object_3 of List_D object
    $o_TmpKey = __GetElement($o_GetKey, "Object_3")
    $o_TmpKey = __InitiateNewArray($o_TmpKey, "List_D_F")
    For $i = 0 To UBound($o_Array) - 1
        __AddElement($o_TmpKey, $i, $o_Array[$i])
    Next
    __AddElement($o_TmpKey, UBound($o_Array), "value_D_F=100")

    ;~~~~ Json_PRETTY_PRINT
    ConsoleWrite(__Json_PRETTY_PRINT($ParseJson) & @Crlf & @Crlf & @Crlf)
    If IsObj($ParseJson) Then $ParseJson = 0    ;~ delete object
    If IsObj($o_Obj) Then $o_Obj = 0            ;~ delete object
EndFunc

 

{
    "Primitive_1": "Test",
    "Primitive_2": true,
    "Primitive_3": false,
    "Primitive_4": null,
    "List_A": [
        "Test",
        true,
        false,
        null,
        {
            "Object_1": {
                "List_A_B": [
                    "Test",
                    true,
                    false,
                    null,
                    "value_A_B=100"
                ]
            }
        }
    ],
    "List_C": [
        "Test",
        true,
        false,
        null,
        "value_C=100"
    ],
    "List_D": [
        {
            "Object_2": {
                "List_D_E": [
                    "Test",
                    true,
                    false,
                    null,
                    "value_D_E=100"
                ]
            },
            "Object_3": {
                "List_D_F": [
                    "Test",
                    true,
                    false,
                    null,
                    "value_D_F=100"
                ]
            }
        }
    ],
    "Empty_object": {}
}

 

Link to comment
Share on other sites

1 hour ago, jugador said:

conversion of @mLipok example using Json2(Version 2) udf

This is nice when it comes to AutoIt code optimalization.
Thanks.

But this is not so nice when it comes to the case we have here:
To show how to create JSON Formatted Structure using DOT NOTATION .
 

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:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

@mLipok by DOT NOTATION if you mean this type of string => ".List_A[4].Object_1.List_A_B[0]"

Json_Put($Obj, ".List_A[4].Object_1.List_A_B[0]", "Test")

then look at Json_Put code you will see use of recursion
so same can be done using this udf just have to write another function for it.

If you look at the above code you will see I first create the structure
to have better control over the json

;~ initialize Array
    Local $o_KeyList[] = ['List_A', 'List_C', 'List_D']
    For $i = 0 To UBound($o_KeyList) - 1
        __InitiateNewArray($ParseJson, $o_KeyList[$i])
    Next
    __InitiateNewObject($ParseJson, 'Empty_object')


 

Edited by jugador
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...