Jump to content
TheXman

A powerful and flexible JSON Processor ( jq )

Recommended Posts

Version History

  • v1.4.3 (2021-01-22)
    • Modified jqExec() and jqExecFile so that when using the option to pass a jq filter file (-f), the adding of the string filter to the command line is suppressed.  Previously, the results would have been correct but the result would have included an error message saying that it couldn't open a file.
       
  • v1.4.2 (2021-01-10)
    • Modified the path to the executable in the jq_example_2.au3 file.  It was pointing to my local directory instead of pointing, generically, to the UDF directory.  That would have caused some to initially be confused because the example script would have exited with an error saying that it could not find the executable.
       
  • v1.4.1 (2021-01-06)
    • Added an additional example file (jq_examples_2.au3) with its associated json data file (nfl_scores_2018_week_01.json). 
       
    • The new examples further highlight the differences between JSON parsers (like the great json.au3 UDF that is based on jsmn) and JSON processors like jq.  Read the information at the top of the new example file for more details about the differences and when you may want to use a JSON processor over a JSON parser.
Edited by TheXman

Share this post


Link to post
Share on other sites

I do not encounter any errors when running any of the examples and haven't encountered any such error using the UDF in any of my other scripts.  Please provide a script that reproduces the error.

Edited by TheXman

Share this post


Link to post
Share on other sites
On ‎3‎/‎27‎/‎2019 at 9:36 PM, TheXman said:

I do not encounter any errors when running any of the examples and haven't encountered any such error using the UDF in any of my other scripts.  Please provide a script that reproduces the error.

#include "jq.au3"

Local $sJson = _
'[{"UPDATE_INSTCODE":"98251","AUTHORORGANIZATION_TEXT":"Enterprise consulting service organization","PRODUCT_CODE":"1178","ORGAN_CODE":"28591XPSS800416","CARDNO":"455872212281239995","ID":"319352E00E934269977B294A4A8C866F","DOSE_UNIT":"ml","YPZH":"1178","VIS_S_NO":"754262","USEWAY_CODE":"1","LAST_DAYS":"1","RX_DT":1522198703000,"UPDATE_INSTNAME":"","PRUDUCT_NAME":"C6H7NAO2","IDCARD":"455872122812999523","PACK_UNIT":"BOX","CREATE_INSTNAME":"","CREATE_DATE":1522847958000,"CARDTYPECODE":"1","PRUDUCT_AMT":"100.8","USEWAY_CODE_NAME":"DISSOLVE","AUTHORORGANIZATION_CODE":"28591XPSS800416","PRUDUCT_P":"25.2","SEXCODE":"2","TOTAL_DOSE":"20","OP_EM_HP_NO":"754262","UPDATE_DATE":1523959163000,"PRE_IDENT":"1","FORM_CODE_NAME":"SOLUTION","PRUDUCT_FRY":"tid","CLIENT_NAME":"ANTICORROSIVE","OP_EM_HP_MARK":"1","CARDTYPENAME":"INSURENCE","PRUDUCT_SPEC":"1000ml*6","FORM_CODE":"4","CREATE_INSTCODE":"98251","USER_NAME":"ADDITIVE","PROCDUTDATE":-389779200000,"PACK_NO":"4","TRADE_NAME":"C6H7NAO2","SINGLE_DOSE":"200","ORGAN_NAME":"Enterprise consulting service organization","MPI":"0","ID2":"1538262","RX_TYPE":"1","RX_TYPE_NAME":" INSECTICIDE","RX_CODE":"1538262","DOC_IDCARD":" ","SEXNAME":"FEMALE"},{"UPDATE_INSTCODE":"98251","AUTHORORGANIZATION_TEXT":"Enterprise consulting service organization","PRODUCT_CODE":"3572","ORGAN_CODE":"28591XPSS800416","CARDNO":"995221245587928123","ID":"E41B24A453634FA2C717DF9C46650028","DOSE_UNIT":"mg","YPZH":"3572","FAC_NAME":"CHEMGUIDEE","VIS_S_NO":"750670","USEWAY_CODE":"1","LAST_DAYS":"7","RX_DT":1521275855000,"UPDATE_INSTNAME":"","PRUDUCT_NAME":"SORBICACIDSODIUMSALT ","IDCARD":"455879995221228123","PACK_UNIT":"BOTTLE","CREATE_INSTNAME":"","CREATE_DATE":1522847948000,"CARDTYPECODE":"1","PRUDUCT_AMT":"163.8","AUTHORORGANIZATION_CODE":"28591XPSS800416","USEWAY_CODE_NAME":"DISSOLVE","PRUDUCT_P":"40.95","SEXCODE":"2","TOTAL_DOSE":"20","OP_EM_HP_NO":"750670","UPDATE_DATE":1522846316000,"PRE_IDENT":"1","FORM_CODE_NAME":"CASPUSLR","PRUDUCT_FRY":"bid","CLIENT_NAME":"ANTICORROSIVE","OP_EM_HP_MARK":"1","CARDTYPENAME":"INSURENCE","PRUDUCT_SPEC":"20mg*14","FORM_CODE":"143","CREATE_INSTCODE":"98251","USER_NAME":"PRODSUPPLER","PROCDUTDATE":-389779200000,"PACK_NO":"4","TRADE_NAME":"SORBICACIDSODIUMSALT ","SINGLE_DOSE":"20","ORGAN_NAME":"Enterprise consulting service organization","MPI":"0","ID2":"1530200","RX_TYPE":"1","RX_TYPE_NAME":" INSECTICIDE","RX_CODE":"1530200","DOC_IDCARD":" ","SEXNAME":"FEMALE"}]' & @CRLF & _
''
Consolewrite(@CRLF & "$sJson=" & $sJson & @CRLF)

_jqInit()
If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF)

local $sOut = _jqCompactPrintJson($sJson)
ConsoleWrite(@CRLF & "Pretty-Print JSON" & @CRLF & $sOut & @CRLF)

Share this post


Link to post
Share on other sites

@Letraindusoir

I cannot reproduce your error.  Maybe you have a corrupt version of the UDF file.  Have you modified the UDF file in ANY way? 

I ran the script below and it runs just fine.

#include "jq.au3"

$sJson = _
'[{"UPDATE_INSTCODE":"98251","AUTHORORGANIZATION_TEXT":"Enterprise consulting service organization","PRODUCT_CODE":"1178","ORGAN_CODE":"28591XPSS800416","CARDNO":"455872212281239995","ID":"319352E00E934269977B294A4A8C866F","DOSE_UNIT":"ml","YPZH":"1178","VIS_S_NO":"754262","USEWAY_CODE":"1","LAST_DAYS":"1","RX_DT":1522198703000,"UPDATE_INSTNAME":"","PRUDUCT_NAME":"C6H7NAO2","IDCARD":"455872122812999523","PACK_UNIT":"BOX","CREATE_INSTNAME":"","CREATE_DATE":1522847958000,"CARDTYPECODE":"1","PRUDUCT_AMT":"100.8","USEWAY_CODE_NAME":"DISSOLVE","AUTHORORGANIZATION_CODE":"28591XPSS800416","PRUDUCT_P":"25.2","SEXCODE":"2","TOTAL_DOSE":"20","OP_EM_HP_NO":"754262","UPDATE_DATE":1523959163000,"PRE_IDENT":"1","FORM_CODE_NAME":"SOLUTION","PRUDUCT_FRY":"tid","CLIENT_NAME":"ANTICORROSIVE","OP_EM_HP_MARK":"1","CARDTYPENAME":"INSURENCE","PRUDUCT_SPEC":"1000ml*6","FORM_CODE":"4","CREATE_INSTCODE":"98251","USER_NAME":"ADDITIVE","PROCDUTDATE":-389779200000,"PACK_NO":"4","TRADE_NAME":"C6H7NAO2","SINGLE_DOSE":"200","ORGAN_NAME":"Enterprise consulting service organization","MPI":"0","ID2":"1538262","RX_TYPE":"1","RX_TYPE_NAME":" INSECTICIDE","RX_CODE":"1538262","DOC_IDCARD":" ","SEXNAME":"FEMALE"},{"UPDATE_INSTCODE":"98251","AUTHORORGANIZATION_TEXT":"Enterprise consulting service organization","PRODUCT_CODE":"3572","ORGAN_CODE":"28591XPSS800416","CARDNO":"995221245587928123","ID":"E41B24A453634FA2C717DF9C46650028","DOSE_UNIT":"mg","YPZH":"3572","FAC_NAME":"CHEMGUIDEE","VIS_S_NO":"750670","USEWAY_CODE":"1","LAST_DAYS":"7","RX_DT":1521275855000,"UPDATE_INSTNAME":"","PRUDUCT_NAME":"SORBICACIDSODIUMSALT ","IDCARD":"455879995221228123","PACK_UNIT":"BOTTLE","CREATE_INSTNAME":"","CREATE_DATE":1522847948000,"CARDTYPECODE":"1","PRUDUCT_AMT":"163.8","AUTHORORGANIZATION_CODE":"28591XPSS800416","USEWAY_CODE_NAME":"DISSOLVE","PRUDUCT_P":"40.95","SEXCODE":"2","TOTAL_DOSE":"20","OP_EM_HP_NO":"750670","UPDATE_DATE":1522846316000,"PRE_IDENT":"1","FORM_CODE_NAME":"CASPUSLR","PRUDUCT_FRY":"bid","CLIENT_NAME":"ANTICORROSIVE","OP_EM_HP_MARK":"1","CARDTYPENAME":"INSURENCE","PRUDUCT_SPEC":"20mg*14","FORM_CODE":"143","CREATE_INSTCODE":"98251","USER_NAME":"PRODSUPPLER","PROCDUTDATE":-389779200000,"PACK_NO":"4","TRADE_NAME":"SORBICACIDSODIUMSALT ","SINGLE_DOSE":"20","ORGAN_NAME":"Enterprise consulting service organization","MPI":"0","ID2":"1530200","RX_TYPE":"1","RX_TYPE_NAME":" INSECTICIDE","RX_CODE":"1530200","DOC_IDCARD":" ","SEXNAME":"FEMALE"}]'
Consolewrite(@CRLF & "$sJson=" & $sJson & @CRLF)

_jqInit("C:\Portable Apps\AutoIt3\Include\MyIncludes\JQ\jq-win64.exe") ;<== Parameter is not needed if jq executable is in current dir or path
If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF)

$sOut = _jqCompactPrintJson($sJson)
ConsoleWrite(@CRLF & "Compact-Print JSON" & @CRLF & $sOut & @CRLF)

$sOut = _jqPrettyPrintJson($sJson)
ConsoleWrite(@CRLF & "Pretty-Print JSON" & @CRLF & $sOut & @CRLF)

Output:

$sJson=[{"UPDATE_INSTCODE":"98251","AUTHORORGANIZATION_TEXT":"Enterprise consulting service organization","PRODUCT_CODE":"1178","ORGAN_CODE":"28591XPSS800416","CARDNO":"455872212281239995","ID":"319352E00E934269977B294A4A8C866F","DOSE_UNIT":"ml","YPZH":"1178","VIS_S_NO":"754262","USEWAY_CODE":"1","LAST_DAYS":"1","RX_DT":1522198703000,"UPDATE_INSTNAME":"","PRUDUCT_NAME":"C6H7NAO2","IDCARD":"455872122812999523","PACK_UNIT":"BOX","CREATE_INSTNAME":"","CREATE_DATE":1522847958000,"CARDTYPECODE":"1","PRUDUCT_AMT":"100.8","USEWAY_CODE_NAME":"DISSOLVE","AUTHORORGANIZATION_CODE":"28591XPSS800416","PRUDUCT_P":"25.2","SEXCODE":"2","TOTAL_DOSE":"20","OP_EM_HP_NO":"754262","UPDATE_DATE":1523959163000,"PRE_IDENT":"1","FORM_CODE_NAME":"SOLUTION","PRUDUCT_FRY":"tid","CLIENT_NAME":"ANTICORROSIVE","OP_EM_HP_MARK":"1","CARDTYPENAME":"INSURENCE","PRUDUCT_SPEC":"1000ml*6","FORM_CODE":"4","CREATE_INSTCODE":"98251","USER_NAME":"ADDITIVE","PROCDUTDATE":-389779200000,"PACK_NO":"4","TRADE_NAME":"C6H7NAO2","SINGLE_DOSE":"200","ORGAN_NAME":"Enterprise consulting service organization","MPI":"0","ID2":"1538262","RX_TYPE":"1","RX_TYPE_NAME":" INSECTICIDE","RX_CODE":"1538262","DOC_IDCARD":" ","SEXNAME":"FEMALE"},{"UPDATE_INSTCODE":"98251","AUTHORORGANIZATION_TEXT":"Enterprise consulting service organization","PRODUCT_CODE":"3572","ORGAN_CODE":"28591XPSS800416","CARDNO":"995221245587928123","ID":"E41B24A453634FA2C717DF9C46650028","DOSE_UNIT":"mg","YPZH":"3572","FAC_NAME":"CHEMGUIDEE","VIS_S_NO":"750670","USEWAY_CODE":"1","LAST_DAYS":"7","RX_DT":1521275855000,"UPDATE_INSTNAME":"","PRUDUCT_NAME":"SORBICACIDSODIUMSALT ","IDCARD":"455879995221228123","PACK_UNIT":"BOTTLE","CREATE_INSTNAME":"","CREATE_DATE":1522847948000,"CARDTYPECODE":"1","PRUDUCT_AMT":"163.8","AUTHORORGANIZATION_CODE":"28591XPSS800416","USEWAY_CODE_NAME":"DISSOLVE","PRUDUCT_P":"40.95","SEXCODE":"2","TOTAL_DOSE":"20","OP_EM_HP_NO":"750670","UPDATE_DATE":1522846316000,"PRE_IDENT":"1","FORM_CODE_NAME":"CASPUSLR","PRUDUCT_FRY":"bid","CLIENT_NAME":"ANTICORROSIVE","OP_EM_HP_MARK":"1","CARDTYPENAME":"INSURENCE","PRUDUCT_SPEC":"20mg*14","FORM_CODE":"143","CREATE_INSTCODE":"98251","USER_NAME":"PRODSUPPLER","PROCDUTDATE":-389779200000,"PACK_NO":"4","TRADE_NAME":"SORBICACIDSODIUMSALT ","SINGLE_DOSE":"20","ORGAN_NAME":"Enterprise consulting service organization","MPI":"0","ID2":"1530200","RX_TYPE":"1","RX_TYPE_NAME":" INSECTICIDE","RX_CODE":"1530200","DOC_IDCARD":" ","SEXNAME":"FEMALE"}]

Compact-Print JSON
[{"UPDATE_INSTCODE":"98251","AUTHORORGANIZATION_TEXT":"Enterprise consulting service organization","PRODUCT_CODE":"1178","ORGAN_CODE":"28591XPSS800416","CARDNO":"455872212281239995","ID":"319352E00E934269977B294A4A8C866F","DOSE_UNIT":"ml","YPZH":"1178","VIS_S_NO":"754262","USEWAY_CODE":"1","LAST_DAYS":"1","RX_DT":1522198703000,"UPDATE_INSTNAME":"","PRUDUCT_NAME":"C6H7NAO2","IDCARD":"455872122812999523","PACK_UNIT":"BOX","CREATE_INSTNAME":"","CREATE_DATE":1522847958000,"CARDTYPECODE":"1","PRUDUCT_AMT":"100.8","USEWAY_CODE_NAME":"DISSOLVE","AUTHORORGANIZATION_CODE":"28591XPSS800416","PRUDUCT_P":"25.2","SEXCODE":"2","TOTAL_DOSE":"20","OP_EM_HP_NO":"754262","UPDATE_DATE":1523959163000,"PRE_IDENT":"1","FORM_CODE_NAME":"SOLUTION","PRUDUCT_FRY":"tid","CLIENT_NAME":"ANTICORROSIVE","OP_EM_HP_MARK":"1","CARDTYPENAME":"INSURENCE","PRUDUCT_SPEC":"1000ml*6","FORM_CODE":"4","CREATE_INSTCODE":"98251","USER_NAME":"ADDITIVE","PROCDUTDATE":-389779200000,"PACK_NO":"4","TRADE_NAME":"C6H7NAO2","SINGLE_DOSE":"200","ORGAN_NAME":"Enterprise consulting service organization","MPI":"0","ID2":"1538262","RX_TYPE":"1","RX_TYPE_NAME":" INSECTICIDE","RX_CODE":"1538262","DOC_IDCARD":" ","SEXNAME":"FEMALE"},{"UPDATE_INSTCODE":"98251","AUTHORORGANIZATION_TEXT":"Enterprise consulting service organization","PRODUCT_CODE":"3572","ORGAN_CODE":"28591XPSS800416","CARDNO":"995221245587928123","ID":"E41B24A453634FA2C717DF9C46650028","DOSE_UNIT":"mg","YPZH":"3572","FAC_NAME":"CHEMGUIDEE","VIS_S_NO":"750670","USEWAY_CODE":"1","LAST_DAYS":"7","RX_DT":1521275855000,"UPDATE_INSTNAME":"","PRUDUCT_NAME":"SORBICACIDSODIUMSALT ","IDCARD":"455879995221228123","PACK_UNIT":"BOTTLE","CREATE_INSTNAME":"","CREATE_DATE":1522847948000,"CARDTYPECODE":"1","PRUDUCT_AMT":"163.8","AUTHORORGANIZATION_CODE":"28591XPSS800416","USEWAY_CODE_NAME":"DISSOLVE","PRUDUCT_P":"40.95","SEXCODE":"2","TOTAL_DOSE":"20","OP_EM_HP_NO":"750670","UPDATE_DATE":1522846316000,"PRE_IDENT":"1","FORM_CODE_NAME":"CASPUSLR","PRUDUCT_FRY":"bid","CLIENT_NAME":"ANTICORROSIVE","OP_EM_HP_MARK":"1","CARDTYPENAME":"INSURENCE","PRUDUCT_SPEC":"20mg*14","FORM_CODE":"143","CREATE_INSTCODE":"98251","USER_NAME":"PRODSUPPLER","PROCDUTDATE":-389779200000,"PACK_NO":"4","TRADE_NAME":"SORBICACIDSODIUMSALT ","SINGLE_DOSE":"20","ORGAN_NAME":"Enterprise consulting service organization","MPI":"0","ID2":"1530200","RX_TYPE":"1","RX_TYPE_NAME":" INSECTICIDE","RX_CODE":"1530200","DOC_IDCARD":" ","SEXNAME":"FEMALE"}]

Pretty-Print JSON
[
  {
    "UPDATE_INSTCODE": "98251",
    "AUTHORORGANIZATION_TEXT": "Enterprise consulting service organization",
    "PRODUCT_CODE": "1178",
    "ORGAN_CODE": "28591XPSS800416",
    "CARDNO": "455872212281239995",
    "ID": "319352E00E934269977B294A4A8C866F",
    "DOSE_UNIT": "ml",
    "YPZH": "1178",
    "VIS_S_NO": "754262",
    "USEWAY_CODE": "1",
    "LAST_DAYS": "1",
    "RX_DT": 1522198703000,
    "UPDATE_INSTNAME": "",
    "PRUDUCT_NAME": "C6H7NAO2",
    "IDCARD": "455872122812999523",
    "PACK_UNIT": "BOX",
    "CREATE_INSTNAME": "",
    "CREATE_DATE": 1522847958000,
    "CARDTYPECODE": "1",
    "PRUDUCT_AMT": "100.8",
    "USEWAY_CODE_NAME": "DISSOLVE",
    "AUTHORORGANIZATION_CODE": "28591XPSS800416",
    "PRUDUCT_P": "25.2",
    "SEXCODE": "2",
    "TOTAL_DOSE": "20",
    "OP_EM_HP_NO": "754262",
    "UPDATE_DATE": 1523959163000,
    "PRE_IDENT": "1",
    "FORM_CODE_NAME": "SOLUTION",
    "PRUDUCT_FRY": "tid",
    "CLIENT_NAME": "ANTICORROSIVE",
    "OP_EM_HP_MARK": "1",
    "CARDTYPENAME": "INSURENCE",
    "PRUDUCT_SPEC": "1000ml*6",
    "FORM_CODE": "4",
    "CREATE_INSTCODE": "98251",
    "USER_NAME": "ADDITIVE",
    "PROCDUTDATE": -389779200000,
    "PACK_NO": "4",
    "TRADE_NAME": "C6H7NAO2",
    "SINGLE_DOSE": "200",
    "ORGAN_NAME": "Enterprise consulting service organization",
    "MPI": "0",
    "ID2": "1538262",
    "RX_TYPE": "1",
    "RX_TYPE_NAME": " INSECTICIDE",
    "RX_CODE": "1538262",
    "DOC_IDCARD": " ",
    "SEXNAME": "FEMALE"
  },
  {
    "UPDATE_INSTCODE": "98251",
    "AUTHORORGANIZATION_TEXT": "Enterprise consulting service organization",
    "PRODUCT_CODE": "3572",
    "ORGAN_CODE": "28591XPSS800416",
    "CARDNO": "995221245587928123",
    "ID": "E41B24A453634FA2C717DF9C46650028",
    "DOSE_UNIT": "mg",
    "YPZH": "3572",
    "FAC_NAME": "CHEMGUIDEE",
    "VIS_S_NO": "750670",
    "USEWAY_CODE": "1",
    "LAST_DAYS": "7",
    "RX_DT": 1521275855000,
    "UPDATE_INSTNAME": "",
    "PRUDUCT_NAME": "SORBICACIDSODIUMSALT ",
    "IDCARD": "455879995221228123",
    "PACK_UNIT": "BOTTLE",
    "CREATE_INSTNAME": "",
    "CREATE_DATE": 1522847948000,
    "CARDTYPECODE": "1",
    "PRUDUCT_AMT": "163.8",
    "AUTHORORGANIZATION_CODE": "28591XPSS800416",
    "USEWAY_CODE_NAME": "DISSOLVE",
    "PRUDUCT_P": "40.95",
    "SEXCODE": "2",
    "TOTAL_DOSE": "20",
    "OP_EM_HP_NO": "750670",
    "UPDATE_DATE": 1522846316000,
    "PRE_IDENT": "1",
    "FORM_CODE_NAME": "CASPUSLR",
    "PRUDUCT_FRY": "bid",
    "CLIENT_NAME": "ANTICORROSIVE",
    "OP_EM_HP_MARK": "1",
    "CARDTYPENAME": "INSURENCE",
    "PRUDUCT_SPEC": "20mg*14",
    "FORM_CODE": "143",
    "CREATE_INSTCODE": "98251",
    "USER_NAME": "PRODSUPPLER",
    "PROCDUTDATE": -389779200000,
    "PACK_NO": "4",
    "TRADE_NAME": "SORBICACIDSODIUMSALT ",
    "SINGLE_DOSE": "20",
    "ORGAN_NAME": "Enterprise consulting service organization",
    "MPI": "0",
    "ID2": "1530200",
    "RX_TYPE": "1",
    "RX_TYPE_NAME": " INSECTICIDE",
    "RX_CODE": "1530200",
    "DOC_IDCARD": " ",
    "SEXNAME": "FEMALE"
  }
]

 

Edited by TheXman

Share this post


Link to post
Share on other sites

 

19 hours ago, TheXman said:

@Letraindusoir

I cannot reproduce your error.  Maybe you have a corrupt version of the UDF file.  Have you modified the UDF file in ANY way? 

I ran the script below and it runs just fine.

#include "jq.au3"

$sJson = _
'[{"UPDATE_INSTCODE":"98251","AUTHORORGANIZATION_TEXT":"Enterprise consulting service organization","PRODUCT_CODE":"1178","ORGAN_CODE":"28591XPSS800416","CARDNO":"455872212281239995","ID":"319352E00E934269977B294A4A8C866F","DOSE_UNIT":"ml","YPZH":"1178","VIS_S_NO":"754262","USEWAY_CODE":"1","LAST_DAYS":"1","RX_DT":1522198703000,"UPDATE_INSTNAME":"","PRUDUCT_NAME":"C6H7NAO2","IDCARD":"455872122812999523","PACK_UNIT":"BOX","CREATE_INSTNAME":"","CREATE_DATE":1522847958000,"CARDTYPECODE":"1","PRUDUCT_AMT":"100.8","USEWAY_CODE_NAME":"DISSOLVE","AUTHORORGANIZATION_CODE":"28591XPSS800416","PRUDUCT_P":"25.2","SEXCODE":"2","TOTAL_DOSE":"20","OP_EM_HP_NO":"754262","UPDATE_DATE":1523959163000,"PRE_IDENT":"1","FORM_CODE_NAME":"SOLUTION","PRUDUCT_FRY":"tid","CLIENT_NAME":"ANTICORROSIVE","OP_EM_HP_MARK":"1","CARDTYPENAME":"INSURENCE","PRUDUCT_SPEC":"1000ml*6","FORM_CODE":"4","CREATE_INSTCODE":"98251","USER_NAME":"ADDITIVE","PROCDUTDATE":-389779200000,"PACK_NO":"4","TRADE_NAME":"C6H7NAO2","SINGLE_DOSE":"200","ORGAN_NAME":"Enterprise consulting service organization","MPI":"0","ID2":"1538262","RX_TYPE":"1","RX_TYPE_NAME":" INSECTICIDE","RX_CODE":"1538262","DOC_IDCARD":" ","SEXNAME":"FEMALE"},{"UPDATE_INSTCODE":"98251","AUTHORORGANIZATION_TEXT":"Enterprise consulting service organization","PRODUCT_CODE":"3572","ORGAN_CODE":"28591XPSS800416","CARDNO":"995221245587928123","ID":"E41B24A453634FA2C717DF9C46650028","DOSE_UNIT":"mg","YPZH":"3572","FAC_NAME":"CHEMGUIDEE","VIS_S_NO":"750670","USEWAY_CODE":"1","LAST_DAYS":"7","RX_DT":1521275855000,"UPDATE_INSTNAME":"","PRUDUCT_NAME":"SORBICACIDSODIUMSALT ","IDCARD":"455879995221228123","PACK_UNIT":"BOTTLE","CREATE_INSTNAME":"","CREATE_DATE":1522847948000,"CARDTYPECODE":"1","PRUDUCT_AMT":"163.8","AUTHORORGANIZATION_CODE":"28591XPSS800416","USEWAY_CODE_NAME":"DISSOLVE","PRUDUCT_P":"40.95","SEXCODE":"2","TOTAL_DOSE":"20","OP_EM_HP_NO":"750670","UPDATE_DATE":1522846316000,"PRE_IDENT":"1","FORM_CODE_NAME":"CASPUSLR","PRUDUCT_FRY":"bid","CLIENT_NAME":"ANTICORROSIVE","OP_EM_HP_MARK":"1","CARDTYPENAME":"INSURENCE","PRUDUCT_SPEC":"20mg*14","FORM_CODE":"143","CREATE_INSTCODE":"98251","USER_NAME":"PRODSUPPLER","PROCDUTDATE":-389779200000,"PACK_NO":"4","TRADE_NAME":"SORBICACIDSODIUMSALT ","SINGLE_DOSE":"20","ORGAN_NAME":"Enterprise consulting service organization","MPI":"0","ID2":"1530200","RX_TYPE":"1","RX_TYPE_NAME":" INSECTICIDE","RX_CODE":"1530200","DOC_IDCARD":" ","SEXNAME":"FEMALE"}]'
Consolewrite(@CRLF & "$sJson=" & $sJson & @CRLF)

_jqInit("C:\Portable Apps\AutoIt3\Include\MyIncludes\JQ\jq-win64.exe") ;<== Parameter is not needed if jq executable is in current dir or path
If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF)

$sOut = _jqCompactPrintJson($sJson)
ConsoleWrite(@CRLF & "Compact-Print JSON" & @CRLF & $sOut & @CRLF)

$sOut = _jqPrettyPrintJson($sJson)
ConsoleWrite(@CRLF & "Pretty-Print JSON" & @CRLF & $sOut & @CRLF)

 

 

Thanks! Run the above code,New problems have arisen.....

20190329200055.png.6334b83ce76f8b94c01075fca3ec9ddd.png

I think there's a problem with the version of autoit or scite ?

Share this post


Link to post
Share on other sites
58 minutes ago, Letraindusoir said:

I think there's a problem with the version of autoit or scite ?

and you think this ...why? 

You also never told us if it is now working for you and how you solved your previous issue...  care to share?

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.
  :)

Share this post


Link to post
Share on other sites
2 hours ago, Letraindusoir said:

 

Thanks! Run the above code,New problems have arisen.....

20190329200055.png.6334b83ce76f8b94c01075fca3ec9ddd.png

I think there's a problem with the version of autoit or scite ?

sorry,It 's my mistake.

_jqInit("C:\Portable Apps\AutoIt3\Include\MyIncludes\JQ\jq-win64.exe") ;<== Parameter is not needed if jq executable is in current dir or path

on my here, jq executable is in Scriptdir.so,It should be:

_jqInit()

 

Share this post


Link to post
Share on other sites

The UDF has been added to the wiki.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

In jqInit() the code for searching the jq-winXX.exe files is not language proof.

You use the "where" command to search for the files in the @ScriptDir

$iPid = Run(StringFormat("where jq-win%s.exe", $s32or64), @ScriptDir, @SW_HIDE, $STDERR_MERGED)

But the return of where.exe can be localized depending of OS language.

for example in my german OS, jqInit() does not give an error although no file has been found:

$sExePath = _jqInit()

If @error Then
    ConsoleWrite(StringFormat("ERROR: Unable to initialize jq - @error = %s", @error) & @CRLF)
    Exit -1
EndIf

ConsoleWrite(StringFormat("jq Path        = %s", $sExePath)       & @CRLF)
ConsoleWrite(StringFormat("jq UDF Version = %s", _jqUdfVersion()) & @CRLF)
ConsoleWrite(StringFormat("jq Version     = %s", _jqVersion())    & @CRLF)
Quote

jq Path        = INFORMATION: Es konnten keine Dateien mit dem angegebenen
jq UDF Version = 1.4.0
jq Version     = ERROR: Unable to execute jq

jq_debug_log.txt:

Quote

2020-09-21 17:10:19    Searching for jq executable
2020-09-21 17:10:19    jq executable found = INFORMATION: Es konnten keine Dateien mit dem angegebenen

 

I suggest you use a simple FileExists if no Path was supplied:

;If exe path was supplied
    If StringStripWS($sExePath, $STR_STRIPLEADING + $STR_STRIPTRAILING ) <> "" Then
        If $__jq_gbDebugging Then __jqWriteLogLine(StringFormat("Exe path supplied to _jqInit = %s", $sExePath))

        ;If the file does not exist
        If Not FileExists($sExePath) Then Return SetError(2, 0, "")

        ;Set global var and return
        $__jq_gsJqExeFilePath = $sExePath
    Else
        If $__jq_gbDebugging Then __jqWriteLogLine("Searching for jq executable")

        $sExePath = @ScriptDir&"\jq-win"&$s32or64&".exe"

        If Not FileExists($sExePath) Then
            If $__jq_gbDebugging Then __jqWriteLogLine("jq executable not found")
            Return SetError(2, 0, "")
        EndIf
        
        If $__jq_gbDebugging Then __jqWriteLogLine(StringFormat("jq executable found = %s", $sExePath))
        $__jq_gsJqExeFilePath = $sExePath
        
        
;~      not OS language proof
        
;~      ;Search for exe
;~      $iPid = Run(StringFormat("where jq-win%s.exe", $s32or64), @ScriptDir, @SW_HIDE, $STDERR_MERGED)
;~      If @error Then Return SetError(3, 0, "")

;~      ;Wait for command to close and get output
;~      ProcessWaitClose($iPid, 10)
;~      $sCmdOutput = StdoutRead($iPid)
;~      ConsoleWrite($sCmdOutput & @CRLF)
;~      ;If exe not found
;~      If StringInStr($sCmdOutput, "Could not find") Then
;~          If $__jq_gbDebugging Then __jqWriteLogLine("jq executable not found")
;~          Return SetError(1, 0, "")
;~      EndIf

;~      ;Parse first line from output
;~      $aResult = StringRegExp($sCmdOutput, ".*", 3)
;~      If Not IsArray($aResult) Then Return SetError(1, 0, "")

;~      ;Set global var
;~      If $__jq_gbDebugging Then __jqWriteLogLine(StringFormat("jq executable found = %s", $aResult[0]))
;~      $__jq_gsJqExeFilePath = $aResult[0]
        
        
        
    EndIf

Is there a reason you do the whole Run/where/StdoutRead block when no Path was supplied?

 

Edited by qsek

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites

Also i would add that this command line approach is quite slow.

I got 500 ms+ for each query.

Can be very slow if you have loops with queries.

Isn't there a COM or DLL version?


Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites
36 minutes ago, qsek said:

Also i would add that this command line approach is quite slow.

If you read the first post, I said that if you only need to parse JSON, then there are faster solutions.  jq is a JSON PROCESSOR not just a PARSER.  So if you need to actually do some processing of JSON, it is much faster, easier, and will save numerous lines of code.

For example, I have a NFL pool that automatically updates its scores.  The source is a large JSON file that I access by web API. It has all of the matchups, scores, and stats for the current week's games, in realtime.  In 1 jq call (one line of executable code), I can filter just the games that have completed so far, get the winning teams, and the scores.  Being able to do it in under 1 second is much better than all of the logic that would be required to do the same thing after parsing the necessary data and the using AutoIt to process all of that parsed data to get the required results.  Processing JSON and parsing JSON data are 2 totally different things.

If you are doing any calculations or transformations of the JSON in your loop, then it could probably all be done with a single jq call (at least the JSON part).  That's the difference between parsing and processing the JSON.

 

36 minutes ago, qsek said:

Isn't there a COM or DLL version?

I haven't found one.  It is open source so if you have the skill, you could always write your own DLL or COM wrapper.

Edited by TheXman

Share this post


Link to post
Share on other sites

@qsek

If you don't find a COM or DLL you can always turn to PS.

Example :

Quote

$sJson = '{"fruits":[{"Apple":{"color":"Red","season":"Fall"}}, {"Banana":{"color":"Yellow","season":"Summer"}}]}' | ConvertFrom-Json

$sJson.fruits | select -expand *

 


Share this post


Link to post
Share on other sites
22 hours ago, qsek said:

Isn't there a COM or DLL version?

https://www.chilkatsoft.com/refdoc/xChilkatJsonArrayRef.html
No License Required for JsonArray

https://www.chilkatsoft.com/refdoc/xChilkatJsonObjectRef.html
No License Required for JsonObject

And AutoIt UDF:

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIt and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
Include Dependency Tree (Tool for analyzing script relations)
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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 *

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 *

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

"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: 2021-01-03

Share this post


Link to post
Share on other sites
Posted (edited)

What's New in v1.4.1

  • Added an additional example file (jq_examples_2.au3) with its associated json data file (nfl_scores_2018_week_01.json). 
     
  • The new examples further highlight the differences between JSON parsers (like the great json.au3 UDF that is based on jsmn) and JSON processors like jq.  Read the information at the top of the new example file for more details about the differences and when you may want to use a JSON processor over a JSON parser.
Edited by TheXman

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By TheXman
      This UDF brings the power and flexibility of jq to AutoIt scripts.  jq is an open-source, powerful, and flexible command-line based JSON processor.  As it says on their website, jq is like 'sed' for JSON.  jq can be used for the simplest of tasks like retrieving JSON objects and values (parsing), to very advanced JSON processing using its numerous built-in functions and conditional processing.  Its built-in functions can handle math, selection, conditional processing, mapping, object and array manipulation, flattening, reduction, grouping, and much more.  You can even create your own jq functions.  You can learn more about jq and even play with it in real-time, using jq's online jq playground, all on their website.
      Here and some helpful links to get you more familiar with jq, what can be done with it, its built-in functions, and its syntax.
      jq Website: https://stedolan.github.io/jq/ jq Manual: https://stedolan.github.io/jq/manual/ jqWiki (FAQ, Cookbook, Advanced Topics) https://github.com/stedolan/jq/wiki jq Online Testing Playground: https://jqplay.org/ jq is a single 32 or 64 bit executable that has no other dependencies.  Just like using the SQLite UDF, the only requirement to use this UDF is that the jq executable reside in a location in which the UDF can execute it.  The latest win32 & win64 versions have been included in the UDF download.  You can always get newer versions from the jq website.
      I don't consider this UDF as a replacement for some of the other JSON UDFs like the one based on JSMN.  If speed and simple JSON parsing are your primary goals, then other UDFs may be a better choice.  However, if you like having the power to do just about anything related to JSON processing/manipulation, using a single UDF, then jq may be worth checking out.  It can be used by novices and experts alike.  Below, is a brief explanation of how jq works, how to use the jq UDF, and a few examples of how to do some simple tasks.  If you want to learn more about jq and what it can do, I would highly suggest checking out the jq website and some of the other resources listed above.
      jq at a high level
      Like 'sed', jq reads JSON in, either through STDIN or one or more files, processes it thru one or more "filters", and outputs the results.  You can, optionally, supply "options" that affect how it reads the input, where it gets its "filters", and how it writes its output.  It looks a little like this:
      JSON ---> jq processor (using supplied filters and options) ---> Output
      So in jq lingo, you basically use "Filters" to tell jq what you want it to do.  So in the UDF file, that is why the main functions ( _jqExec() and _jqExecFile() ) refer to filters and options.  Please make note that jq works with relatively strict JSON.  This means that all JSON read must be conform to the standard.  Luckily, jq is pretty good at identifying where a format error exists in non standard JSON.
      The jq UDF
      There are 2 main funtions in the UDF file, _jqExec and jqExecFile.  With these 2 functions, you can pretty much do anything that jq can do.  The only difference between to two functions is whether the JSON is supplied by a string or a file.  The 2 primary functions simply call the jq executable with the supplied information, after properly formatting the parameters.  There are additional functions in the UDF to easily pretty-print your json, compact-print your json, dump the json data with its associated paths, and see if specific JSON keys exist, but they all just execute the _jqExec or _jqExecFile function with the proper filter.  There are also a couple of extra functions to display what version of the UDF and jq executable you are currently using.  There are also a couple of functions to enable and disable logging of jq information for debugging purposes.  Most of the jq UDF file functions return an @error if unsuccessful.  Some also include @extended info.  Please see the actual function headers for more information on their usage and return values.
      The 2 primary functions below just format your jq request and pass it on the jq executable.  The functions will also properly escape double quotes (") that are used in the filter.  For most simple tasks, you just need to supply the JSON source and a filter.
      _jqExec($sJson, $sFilter, $sOptions = Default, $sWorkingDir = Default) Or _jqExecFile($sJsonFile, $sFilter, $sOptions = Default, $sWorkingDir = Default) Using jq in your script
      As stated earlier, the jq executable must reside somewhere where the script can locate and execute it.  The _jqInit() function always has to be executed before any jq processing occurs.  _jqInit() merely locates the executable or uses the supplied path.  It also clears any previous debug log.  The jq UDF folder contains a jq example script that has several examples to how to do some of the most common JSON processing tasks.  Here are a few examples to get you started:

      How to pretty-print some JSON
      #include "jq.au3" _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"fruits":[{"Apple":{"color":"Red","season":"Fall"}}, {"Banana":{"color":"Yellow","season":"Summer"}}]}' $sCmdOutput = _jqPrettyPrintJson($sJson) ConsoleWrite(@CRLF & "Pretty-Print JSON" & @CRLF & $sCmdOutput & @CRLF) How to compact-print some JSON
      #include "jq.au3" _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{ "fruits" : [{"Apple" : {"color":"Red","season":"Fall"}}, {"Banana":{"color":"Yellow","season":"Summer"}}]}' $sCmdOutput = _jqCompactPrintJson($sJson) ConsoleWrite(@CRLF & "Compact-Print JSON" & @CRLF & $sCmdOutput & @CRLF) Dump JSON data (paths and values)
      #include "jq.au3" _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{ "fruits" : [{"Apple" : {"color":"Red","season":"Fall"}}, {"Banana":{"color":"Yellow","season":"Summer"}}]}' $sCmdOutput = _jqDump($sJson) ConsoleWrite(@CRLF & "Dump JSON paths and values" & @CRLF & $sCmdOutput & @CRLF) How to GET JSON values
      #include "jq.au3" _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple" : {"color":"Red","season":"Fall"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = '.Banana.color' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Get color of banana" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) or
      #include "jq.au3" _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple" : {"color":"Red","season":"Fall"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = 'getpath(["Banana", "color"])' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Get color of banana" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF)  
      Check for the existence of a key
      #include "jq.au3" _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple":{"color":"Red","season":"Fall"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = '.Banana | has("color")' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Check for existence of color key within Banana object" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) Count of how many Items in an object
      #include "jq.au3" _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple":{"color":"Red"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = '.Banana | length' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("How many items in the Banana object" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) How to PUT/Create/Modify JSON
      #include "jq.au3" _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sInput = "" $sFilter = 'setpath(["Apple","color"];"Red") | setpath(["Banana","color"];"Yellow") | setpath(["Banana","season"];"Summer")' $sOptions = '-n' ;required if no input supplied $sCmdOutput = _jqExec($sInput, $sFilter, $sOptions) ConsoleWrite("Update/Create JSON" & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & @CRLF & $sCmdOutput & @CRLF) List all of the fruits (top-level keys)
      #include "jq.au3" _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple":{"color":"Red"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = 'keys | .[]' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("List all top-level keys (fruits)" & @CRLF) ConsoleWrite("Input : " & $sJson & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & @CRLF & $sCmdOutput & @CRLF) Calculate the sum of all of the objects' price * qty
      #include "jq.au3" _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '[{"id":1,"price":20.00,"qty":10},{"id":2,"price":15.00,"qty":20.25},{"id":3,"price":10.50,"qty":30}]' $sFilter = 'map(.price * .qty) | add' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Calculate the sum of all of the objects' price * qty" & @CRLF) ConsoleWrite("Input : " & $sJson & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF)
      The examples above, and the ones in the example files, merely scratch the surface of what jq can do.  It may look intimidating at first but it really isn't that bad once you start playing with it.
      If you have any questions regarding the UDF, or how to perform a certain task using jq, I'll try my best to answer them.  Since jq has been around for a while now, there's also several jq-related questions and answers on StackOverflow.
      If you work with JSON, I hope you find this UDF useful as I do.
    • By argumentum
      #include <SQLite.au3> ;-- When SQLite is compiled with the JSON1 extensions it provides builtin tools ;-- for manipulating JSON data stored in the database. ;-- This is a gist showing SQLite return query as a JSON object. ;-- https://www.sqlite.org/json1.html Example() Func Example() _SQLite_Startup() ; "<your path>\sqlite3.dll", False, 1) ; https://www.autoitscript.com/autoit3/docs/libfunctions/_SQLite_Startup.htm _SQLite_Open() ; ...if you can not run this due to errors, get the latest DLL from https://www.sqlite.org/ If _SQLite_Exec(-1, "CREATE TABLE users (id INTEGER PRIMARY KEY NOT NULL, full_name TEXT NOT NULL, email TEXT NOT NULL, created DATE NOT NULL );") Then Return 4 If _SQLite_Exec(-1, 'INSERT INTO users VALUES ' & _ '(1, "Bob McFett", "bmcfett@hunters.com", "32-01-01"),' & _ '(2, "Angus O''Vader","angus.o@destroyers.com", "02-03-04"),' & _ '(3, "Imperator Colin", "c@c.c", "01-01-01");') Then Return 5 ; -- Get query data as a JSON object using the ; -- json_group_object() [1] and json_object() [2] functions. _SQLite_GetTable2d_ArrayToConsole("SELECT" & _ " json_group_object(" & _ " email," & _ " json_object('full_name', full_name, 'created', created)" & _ " ) AS json_result" & _ " FROM (SELECT * FROM users WHERE created > ""02-01-01"");") ; {"bmcfett@hunters.com":{"full_name":"Bob McFett","created":"32-01-01"},"angus.o@destroyers.com":{"full_name":"Angus O'Vader","created":"02-03-04"}} ; -- Get query data as a JSON object using the ; -- json_group_array() function to maintain order. _SQLite_GetTable2d_ArrayToConsole("SELECT" & _ " json_group_array(" & _ " json_object('full_name', full_name, 'created', created)" & _ " ) AS my_json_result_OrAnythingReally" & _ " FROM (SELECT * FROM users ORDER BY created);") ; [{"full_name":"Imperator Colin","created":"01-01-01"},{"full_name":"Angus O'Vader","created":"02-03-04"},{"full_name":"Bob McFett","created":"32-01-01"}] ;-- Links ;-- [1] https://www.sqlite.org/json1.html#jgroupobject ;-- [2] https://www.sqlite.org/json1.html#jobj ; example found at https://gist.github.com/akehrer/481a38477dd0518ec0086ac66e38e0e2 EndFunc ;==>Example Func _SQLite_GetTable2d_ArrayToConsole($sSQL, $hDB = -1) Local $aResult, $iRows, $iColumns If _SQLite_GetTable2d($hDB, $sSQL, $aResult, $iRows, $iColumns) Then ConsoleWrite("! SQLite Error: " & _SQLite_ErrCode($hDB) & @CRLF & "! " & _SQLite_ErrMsg($hDB) & @CRLF) Else _SQLite_Display2DResult($aResult) EndIf ConsoleWrite(@CRLF) EndFunc ;==>_SQLite_GetTable2d_ArrayToConsole Based on this example, you can build your own query. 
      The code has all the explanations.
      Enjoy  
    • By matwachich
      Hi AutoIters!
      Here is my new UDF about GUIs: it's an enhanced mixture of Advanced InputBox (deprecated) and KODA Parser (deprecated), with additional functions.
      What you can do with it:
      Parse KODA files and directly create GUIs (_GUIUtils_CreateFromKODA) Parse a simple JSON form definition to simply create advanced InputBoxes with any amount/type of input controls (_GUIUtils_CreateFromJSON) Created GUIs are returned as Scripting.Dictionary objects, and you have helper functions to access GUIs controls by their names (_GUIUtils_HWnd, _GUIUtils_CtrlID, _GUIUtils_HCtrl ...) A function that can make a GUI created from KODA/JSON (defined by it's $oForm object) and make it a modal InputDialogBox (just like InputBox, but returns all entered data as Scripting.Dictionary object) Functions are documented, and there are some examples.
      Consider this UDF as beta, but since I'm currently using it in a small commercial project, it should become production ready in near future.
      To always get the latest code version, get it from Github (more up to date than this topic).
      Update 04/02/2020:
      New simple application example Fixed focused control handling in _GUIUtils_InputDialog Reset input values before returning from _GUIUtils_InputDialog Fixed CloseOnEsc in _GUIUtils_InputDialog Fixed Input not reset Fixed all ListBox items are selected Project now on GitHub https://github.com/matwachich/autoit-guiutils/
      Update 05/02/2020:
      Support for nodate for Date and Time input controls (pass null value) New handling of focused control _GUIUtils_InputDialog: Now, you can specify the focused control in $oInitialData by setting "controlName:focus" = True Updated documentation of _GUIUtils_InputDialog Update 07/02/2020:
      Bug corrected when setting Data input control Added: abillity to read a single input control New functions (_GUIUtils_GetInputs, _GUIUtils_WriteInputs), documentation completion. Readme file and screenshots on Github Page  
      GUIUtils.zip
    • By Roy_
      Ciao,
      This example reproduces the problem I encounter when sending a post request to an echo server.
      Instead of being sent as text utf8, the data is transmitted base64 encoded.
      Example:
      - json String: '{"firstName":"Jonathan","lastName":"Freeman","loginCount":4,"active": "yes","text":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel volutpat nunc. Maecenas id tempus mi. Morbi ipsum enim, ultricies ac augue sit amet, ullamcorper finibus ex. Vestibulum vel posuere nibh, nec faucibus eros. Nam malesuada non lacus a suscipit. Nulla rhoncus tempus mi quis placerat. Curabitur commodo tincidunt justo quis sollicitudin."}'
      - server response: "data:application/octet-stream;base64,AAAAALgE6QNYAIAAAgAAANQCAAAAAAAAWF8AAAAAAAD0VQAAAAAAAD9APQAAAAAAAwAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAABBAAAAAAABRUAAAAmIZwcAbRt8/LMa9UAAAAAAAAAAGFzIGlkIHRlbXB1cyBtaS4gTW9yYmkgaXBzdW0gZW5pbSwgdWx0cmljaWVzIGFjIGF1Z3VlIHNpdCBhbWV0LCB1bGxhbWNvcnBlciBmaW5pYnVzIGV4LiBWZXN0aWJ1bHVtIHZlbCBwb3N1ZXJlIG5pYmgsIG5lYyBmYXVjaWJ1cyBlcm9zLiBOYW0gbWFsZXN1YWRhIG5vbiBsYWN1cyBhIHN1c2NpcGl0LiBOdWxsYSByaG9uY3VzIHRlbXB1cyBtaSBxdWlzIHBsYWNlcmF0LiBDdXJhYml0dXIgY29tbW9kbyB0aW5jaWR1bnQganVzdG8gcXVpcyBzb2xsaWNpdHVkaW4uIn0="
       
      How can I go about transmitting data in text format utf8?
      Thanks in advance for the help.
      In the zip file:
      - CurlJsonPost.au3: this script
      - Curl.au3: UDF by Ward (thank you!)
      - data.json: json srting for command line test
       
      Note: using Curl.exe with json string saved in a file (utf8 encoded) named data.json, works perfectly
      To try with the command line tool:
      - save data.json in curl\bin directory
      - open cmd.exe and cd to curl\bin directory
      - Enter the following command:
      curl -H "Content-Type: application/json" --data @data.json https://httpbin.org/post
       
      #Include "Curl.au3" Global $_cURL_OutputBuffer Local $sJson = '{"firstName":"Jonathan","lastName":"Freeman","loginCount":4,"active": "yes","text":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel volutpat nunc. Maecenas id tempus mi. Morbi ipsum enim, ultricies ac augue sit amet, ullamcorper finibus ex. Vestibulum vel posuere nibh, nec faucibus eros. Nam malesuada non lacus a suscipit. Nulla rhoncus tempus mi quis placerat. Curabitur commodo tincidunt justo quis sollicitudin."}' Local $iRetCode, $sServerResponse ConsoleWrite("=== Json post test ===" & @LF) ConsoleWrite(StringFormat("Retcode: %s - %s", $iRetCode, Curl_Easy_strerror($iRetCode)) & @LF) ConsoleWrite("Data returned from server" & @LF & @LF) $sServerResponse = JsonPost_Test($sJson, $iRetCode) ConsoleWrite($sServerResponse & @LF) Func JsonPost_Test($sJson, ByRef $iRetCode) ; Init Easy Curl Interface e set url (echo service) Local $oCurl = Curl_Easy_Init() curl_easy_setopt($oCurl, $CURLOPT_URL, "https://httpbin.org/post") ; Set content type header Local $headers = curl_slist_append(0, "Content-Type: application/json") curl_easy_setopt($oCurl, $CURLOPT_HTTPHEADER, $headers) ; Post fields & size curl_easy_setopt($oCurl, $CURLOPT_POSTFIELDS, $sJson) curl_easy_setopt($oCurl, $CURLOPT_POSTFIELDSIZE, StringLen($sJson)) ; Set callbac function to get server response back (see global var $_cURL_OutputBuffer) $hWriteFunc = DllCallbackRegister("WriteFunc_CallBack", "uint:cdecl", "ptr;uint;uint;ptr") curl_easy_setopt($oCurl, $CURLOPT_WRITEFUNCTION, DllCallbackGetPtr($hWriteFunc)) ; Ignore ssl certificates check curl_easy_setopt($oCurl, $CURLOPT_SSL_VERIFYPEER, 0) curl_easy_setopt($oCurl, $CURLOPT_SSL_VERIFYHOST, 0) ; Execute the post request $iRetCode = curl_easy_perform($oCurl) ; Set return trasfer & clear output buffer global var Local $sReturnTransfer = $_cURL_OutputBuffer $_cURL_OutputBuffer = "" Return SetError(0, 0, $sReturnTransfer) EndFunc Func WriteFunc_CallBack($ptr,$nSize,$nMemb,$pStream) Local $vData = DllStructCreate ("byte[" & $nSize*$nMemb & "]",$ptr) $_cURL_OutputBuffer &= BinaryToString(DllStructGetData($vData,1)) Return $nSize*$nMemb EndFunc  
      curlJsonPost.zip
    • By D2thunder
      Hi all, I wasnt active in this Forum forum for Years. 😅
      Since I need something with Json in AutoIt i write a little UDF to save a variable to file to read it with another language - and back. After a while until my other script grows i thought - lets integrate all variables wich is possible, because i want have arrays to.
      This is my first public UDF in Autoit - normaly my AutoIt scripts are quick an dirty.... - like the examples for this udf. - someone want to write nice examples?
      I tried to write this UDF properly, cared for processing speed, low mem consumption as possible, a short code, and a high usability without beeing very familiar with arrays.
      What is it for? - convert nearly all types of variables to a json string for saving it in a file or to an ini. Read it back in to a same formated variable and preserv variable types. All array types are supported with nested arrays, the only restriction is ram and array/stringsize - and time if the array is very big. You can use Filters for variable types and some other options.
      If anyone found a bug or any suggestions, please post it.
       
      get Json.au3 from here Json.au3
       
       
      JsonVar 2019.01.25.1.zip
×
×
  • Create New...