Jump to content

jq UDF - A Powerful & Flexible JSON Processor


TheXman
 Share

Recommended Posts

Version History

  • v1.7.0
    •     Internal code optimizations
    •     Increased query speed
    •     jqExec() and _jqExecFile() now accept string filters with comments (#), as if they were passed in from a file using the -f or --from-file option.
       
  • v1.6.2 (2022-11-30)
    • jq_example_2.au3
      • Modified the script's logging logic to use an internal GUI instead of Notepad.  This eliminates the need for Win11-specific logic since Win11's Notepad uses a different edit control than prior versions.  (Thanks @Danp2for pointing out the change in Win11's Notepad.)
    • No changes were made to the jq.au3 UDF file.
  • v1.6.1 (2022-10-03)

    • Added the ability to recognize the "--from-file" option.  Previously, it would only recognize the "-f" version of the option.
    • Ensured that, in all cases, the JSON string passed to _jqExec() is processed as UTF-8.
  • v1.6.0 (2021-10-02)

    • Added an option to jqDump() and jqDumpFile() that allows you to specify the output notion format. (Bracket-Notation or Dot-Notation)
    • Change the default output notation of jqDump() and jqDumpFile() from bracket-notation to dot-notation.
       
  • v1.5.0 (2021-09-30)

    • Fixed a bug in jqDump() and jqDumpFile that was skipping values that were equal to boolean false.
       

  • 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
Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
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)

Link to comment
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
Link to comment
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 ?

Link to comment
Share on other sites

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

Link to comment
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()

 

Link to comment
Share on other sites

The UDF has been added to the wiki.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 3 months later...

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
Link to comment
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
Link to comment
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
Link to comment
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 *

 

Link to comment
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:
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

  • 3 months later...

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
Link to comment
Share on other sites

New version uploaded.  Click HERE to see version history.

Edited by TheXman
Link to comment
Share on other sites

  • TheXman changed the title to jq UDF - A Powerful & Flexible JSON Processor

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...