Developers Jos Posted January 1, 2019 Developers Share Posted January 1, 2019 I have no issue when more error checking is added to the set of UDF's to avoid it crashing but rather simply returning a error. Let me know when you are done adding it and simply submit it for including in this set. 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 More sharing options...
Acanis Posted January 4, 2019 Share Posted January 4, 2019 Hey @Jos, how can I do this? And Iam not sure, if you want my unexperienced quality in a UDF^^ I would just use something like this: If Not Json_IsObject($Object) Then SetError(1) Return EndIf before every usage (Json_*) of an Object?! Link to comment Share on other sites More sharing options...
Developers Jos Posted January 4, 2019 Developers Share Posted January 4, 2019 (edited) Well you need to think about what you want to return and which errorcode to set for each possible mistake. This can then also be documented. I could imaging that there are many issues that could popup, but the main goal should be that the UDF doesn't crap out whatever you throw at it. When it all is done well we could even consider making it part of the standard UDF library and create the helpfile pages for it, but first things first. Jos Edited January 4, 2019 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
aio Posted January 15, 2019 Share Posted January 15, 2019 Hi everybody and many thanks for sharing this UDF. I'm not an expert in programming languages but I'm trying to get some data from an API that is similar to the $json1 of the following code: #include <json.au3> $json1 = '{"Global Quote":{"01. symbol" : "MSFT","02. open" : "101.9000","03 high" : "102.8716"}}' $Json = Json_Decode($json1) $coord = Json_ObjGet($Json, "Global Quote") ConsoleWrite(Json_ObjGet($coord, "01. symbol") & @LF) ConsoleWrite(Json_ObjGet($coord, "03 high") & @LF) The problem that I'm trying to solve is that the keys of the Json file includes dots (.) and therefore I cannot get the value. The debug console returns with success the value of the key "03 high" where I've eliminated the dot, while doesn't return any value for the "01. symbol". I tried to double quote the keys. I also tried to use Json_Get instead of Json_ObjGet but nothing works. On the other side the Json_Dump shows correctly all the values (for keys with or without dots), but it's too difficult for me to get the solution from the UDF code. #include <json.au3> $data = '{"Global Quote":{"01. symbol" : "MSFT","02. open" : "101.9000","03 high" : "102.8716"}}' Global $object = Json_Decode($data) ConsoleWrite("!== Json_TokenDump ============================================================================================================" & @CRLF) Json_Dump($data) !== Json_TokenDump ============================================================================================================ +-> .Global Quote.01. symbol =MSFT +-> .Global Quote.02. open =101.9000 +-> .Global Quote.03 high =102.8716 >Exit code: 0 Time: 0.3965 Can anyone kindly give me an hint for this problem? Link to comment Share on other sites More sharing options...
Danp2 Posted January 15, 2019 Share Posted January 15, 2019 @aio Have you tried wrapping the key value in quotation marks? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Developers Jos Posted January 15, 2019 Developers Share Posted January 15, 2019 I am afraid the current UDF's have a problem reading keys with a dot inside as the dot is use as separator. 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 More sharing options...
TheXman Posted January 15, 2019 Share Posted January 15, 2019 (edited) There also appears to be a bug with names that begin with a numeric digit. In the snippet below, the first value gets written out and the second value does not. #include <json.au3> $data = '{"Test" : {"Name01" : "Value01", "02Name" : "Value02"}}' $oJson = Json_Decode($data) ConsoleWrite("Value = " & Json_Get($oJson, ".Test.Name01") & @CRLF) ;Displays Value01 ConsoleWrite("Value = " & Json_Get($oJson, ".Test.02Name") & @CRLF) ;Displays <blank> Edited January 15, 2019 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Developers Jos Posted January 15, 2019 Developers Share Posted January 15, 2019 Try: ConsoleWrite("Value = " & Json_Get($oJson, '."Test"."02Name"') & @CRLF) ;Displays <blank> 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 More sharing options...
TheXman Posted January 15, 2019 Share Posted January 15, 2019 (edited) Both of the following correctly display the value: ConsoleWrite("Value = " & Json_Get($oJson, '."Test"."02Name"') & @CRLF) ConsoleWrite("Value = " & Json_Get($oJson, '.Test."02Name"') & @CRLF) For the record, the same is true with bracket notation. Using '[Test][02Name]' does not work but '[Test]["02Name"]' does work. Edited January 15, 2019 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
aio Posted January 15, 2019 Share Posted January 15, 2019 (edited) 2 hours ago, Danp2 said: @aio Have you tried wrapping the key value in quotation marks? Yes, I did. Also retested with the combinations indicated in following posts from Jos and TheXman 2 hours ago, Jos said: I am afraid the current UDF's have a problem reading keys with a dot inside as the dot is use as separator. Jos Sigh..... I was hoping that there was a solution because of Json_Dump () capable of retrieving all the values. Anyway there could be also a problem when keys contains a blankspace like in my case ("Global Quote"). See below, answering to TheXman 2 hours ago, TheXman said: Both of the following correctly display the value: ConsoleWrite("Value = " & Json_Get($oJson, '."Test"."02Name"') & @CRLF) ConsoleWrite("Value = " & Json_Get($oJson, '.Test."02Name"') & @CRLF) For the record, the same is true with bracket notation. Using '[Test][02Name]' does not work but '[Test]["02Name"]' does work. Here is my testing of all combinations using my keys. As far as I understand there could be a bug also when a key contains a blankspace. #include <json.au3> $json1 = '{"Global Quote":{"01. symbol" : "MSFT","02. open" : "101.9000","03 high" : "102.8716"}}' $json1bis = '{"GlobalQuote":{"01. symbol" : "MSFT","02. open" : "101.9000","03 high" : "102.8716"}}' $json1tris = '{"GlobalQuote":{"01. symbol" : "MSFT","02. open" : "101.9000","03high" : "102.8716"}}' $Json = Json_Decode($json1) $Jsonbis = Json_Decode($json1bis) $Jsontris = Json_Decode($json1tris) ; ConsoleWrite("CASE 1 -->> " & Json_Get($Json, '."Global Quote"."03 high"') & @LF) ; ==>> it works!! ; ConsoleWrite("CASE 2 -->> " & Json_Get($Json, '.Global Quote."03 high"') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 2bis -->> " & Json_Get($Jsonbis, '.GlobalQuote."03 high"') & @LF) ; ==>> it works!! ; ConsoleWrite("CASE 3 -->> " & Json_Get($Json, '[Global Quote][03 high]') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 3bis -->> " & Json_Get($Jsonbis, '[GlobalQuote][03 high]') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 3tris -->> " & Json_Get($Jsontris, '[GlobalQuote][03high]') & @LF) ; ==>> it doesn't work!! ; ConsoleWrite("CASE 4 -->> " & Json_Get($Json, '[Global Quote]["03 high"]') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 4bis -->> " & Json_Get($Jsonbis, '[GlobalQuote]["03 high"]') & @LF) ; ==>> it works!! Edited January 16, 2019 by aio Link to comment Share on other sites More sharing options...
Developers Jos Posted January 16, 2019 Developers Share Posted January 16, 2019 I am sure this can be fixed, just needs time to invest in modifying the code not testing for dots inside double quoted strings. 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 More sharing options...
argumentum Posted January 16, 2019 Share Posted January 16, 2019 On 1/4/2019 at 9:08 AM, Jos said: we could even consider making it part of the standard UDF library also, Quote FYI SQLite JSON1 functions work like a charm. so using @TheXman example: #include <SQLite.au3> example() Func example() Const $TEST_JSON = '{"Test" : {"Name01" : "Value01", "02Name" : "Value02", "03 high" : "102.8716"}}' Const $SQLITE_DLL = "C:\...\sqlite3.dll" ;<-- Change to the location of your sqlite dll Local $aRow Local $hQuery ;Init sqlite and create a memory db _SQLite_Startup($SQLITE_DLL, False, 1) If @error Then Exit MsgBox($MB_ICONERROR, "SQLite Error", "Unable to start SQLite. Check existence of DLL") _SQLite_Open() ;Example of validating json (Good return means JSON is well-formed) If _SQLite_Query(-1, "select json('" & $TEST_JSON & "');", $hQuery) = $SQLITE_OK Then While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK ConsoleWrite("Minimized JSON = " & $aRow[0] & @CRLF) WEnd EndIf ;Example of extracting data If _SQLite_Query(-1, "select json_extract('" & $TEST_JSON & "', '$.Test.03 high');", $hQuery) = $SQLITE_OK Then While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK ConsoleWrite("03 high = " & $aRow[0] & @CRLF) WEnd EndIf ;Close db and shutdown sqlite _SQLite_Close() _SQLite_Shutdown() EndFunc If there is to be a native AutoIt UDF for JSON, could the SQLite be used for such ? ( just asking ) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 16, 2019 Developers Share Posted January 16, 2019 I've honestly havent looked at that one yet. Just started with this build and added some stuff to make my life easier. I am fine with any good solution so will have a look at that option. Jos argumentum 1 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 More sharing options...
Developers Jos Posted January 17, 2019 Developers Share Posted January 17, 2019 Well I couldn't resists trying to fix this set of UDF's so think I am getting close with the attached version: expandcollapse popup#include <array.au3> #include <json.au3> $json1 = '{"Global Quote":{"01. symbol" : "MSFT","02. open" : "01.10","03 high" : "10.1"}}' $json1bis = '{"GlobalQuote":{"01. symbol" : "MSFT","02. open" : "02.10","03 high" : "20.2"}}' $json1tris = '{"GlobalQuote":{"01. symbol" : "MSFT","02.open" : "03.10","03high" : "30.3"}}' $Json = Json_Decode($json1) $Jsonbis = Json_Decode($json1bis) $Jsontris = Json_Decode($json1tris) ; ConsoleWrite("!===============================================================================" & @crlf) ConsoleWrite("CASE 1 -->> " & Json_Get($Json, '."Global Quote"."03 high"') & @LF) ; ==>> it works!! ConsoleWrite("CASE 2 -->> " & Json_Get($Json, '.Global Quote."03 high"') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 2bis -->> " & Json_Get($Jsonbis, '.GlobalQuote."03 high"') & @LF) ; ==>> it works!! ConsoleWrite("CASE 2bis2-->> " & Json_Get($Jsonbis, 'GlobalQuote."03 high"') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 2bis3-->> " & Json_Get($Jsonbis, 'GlobalQuote.03 high') & @LF) ; ==>> it doesn't work!! ;~ ; ConsoleWrite("CASE 3 -->> " & Json_Get($Json, '[Global Quote][03 high]') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 3bis -->> " & Json_Get($Jsonbis, '[GlobalQuote][03 high]') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 3tris-->> " & Json_Get($Jsontris, '[GlobalQuote][03high]') & @LF) ; ==>> it doesn't work!! ;~ ; ConsoleWrite("CASE 4 -->> " & Json_Get($Json, '[Global Quote]["03 high"]') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 4bis -->> " & Json_Get($Jsonbis, '[GlobalQuote]["03 high"]') & @LF) ; ==>> it works!!;~ ; ; ConsoleWrite("CASE 1 -->> " & Json_Get($Json, '."Global Quote"."03 high"') & @LF) ; ==>> it works!! ConsoleWrite("CASE 1 -->> " & Json_Get($Json, '."Global Quote"."02. open"') & @LF) ; ==>> it works!! ConsoleWrite("CASE 2 -->> " & Json_Get($Json, '.Global Quote."02. open"') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 2bis -->> " & Json_Get($Jsonbis, '.GlobalQuote."02. open"') & @LF) ; ==>> it works!! ConsoleWrite("CASE 2bis2-->> " & Json_Get($Jsonbis, 'GlobalQuote."02. open"') & @LF) ; ==>> it doesn't work!! ;~ ; ConsoleWrite("CASE 3 -->> " & Json_Get($Json, '[Global Quote][02. open]') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 3bis -->> " & Json_Get($Jsonbis, '[GlobalQuote][02. open]') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 3tris-->> " & Json_Get($Jsontris, '[GlobalQuote][02.open]') & @LF) ; ==>> it doesn't work!! ;~ ; ConsoleWrite("CASE 4 -->> " & Json_Get($Json, '[Global Quote]["02. open"]') & @LF) ; ==>> it doesn't work!! ConsoleWrite("CASE 4bis -->> " & Json_Get($Jsonbis, '[GlobalQuote]["02. open"]') & @LF) ; ==>> it works!!;~ ; Results: !=============================================================================== CASE 1 -->> 10.1 CASE 2 -->> 10.1 CASE 2bis -->> 20.2 CASE 2bis2-->> 20.2 CASE 2bis3-->> 20.2 CASE 3 -->> 10.1 CASE 3bis -->> 20.2 CASE 3tris-->> 30.3 CASE 4 -->> 10.1 CASE 4bis -->> 20.2 CASE 1 -->> 10.1 CASE 1 -->> 01.10 CASE 2 -->> 01.10 CASE 2bis -->> 02.10 CASE 2bis2-->> 02.10 CASE 3 -->> 01.10 CASE 3bis -->> 02.10 CASE 3tris-->> 03.10 CASE 4 -->> 01.10 CASE 4bis -->> 02.10 @aio and others, could you have a spin with this version to see whether anything is broken? Jos Json.au3 aio, Jokerman and argumentum 2 1 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 More sharing options...
aio Posted January 17, 2019 Share Posted January 17, 2019 7 hours ago, Jos said: Well I couldn't resists trying to fix this set of UDF's so think I am getting close with the attached version: ............... @aio and others, could you have a spin with this version to see whether anything is broken? Jos Json.au3 Tested with functions Json_Get and Json_ObjGet. It works in both functions with dots and blankspaces. Don't know if more extensive tests should be performed to guarantee that everything else still works fine. @Jos Many thanks and sorry for interrupting your schedule. Link to comment Share on other sites More sharing options...
satanico64 Posted July 2, 2019 Share Posted July 2, 2019 Hi guys, is there another way to add a value to an array objet in a json, without using ubound like i did here ? if StringInStr($text,"Case") then json_put($js, '["Cases"][' & ubound(json_objget($js,'Cases')) & ']',$text) elseif StringInStr($text,"Quote") then json_put($js, '["Quotes"][' & ubound(json_objget($js,'Quotes')) & ']',$text) EndIf it works but maybe not the best way to do that... { "Cases": [ " Case 156910" ], "Quotes": [ "[READ] Quote 483796", "[READ] Quote 440329", "[READ] Quote 440238" ] } thanks Link to comment Share on other sites More sharing options...
LukeWCS Posted July 15, 2019 Share Posted July 15, 2019 (edited) @Ward @Jos Hi As a feedback for both of you: On Nexus Mods I use in my program "QMod SAM" your JSON UDF and have there in the tab "description" a link to this topic set here. So also at this point: Thanks for this UDF! QMod SAM (see "Special Thanks:") P.S.: Jos, are your recent changes stable so far that I can take over your latest version? Currently I am using the official version of the startup post. Edited July 15, 2019 by LukeWCS Link to comment Share on other sites More sharing options...
Letraindusoir Posted July 15, 2019 Share Posted July 15, 2019 (edited) Response={"value":null} Response={"value":""} Response={"value":[]} Response={"value":{}} Response={"value":True} Response={"value":1000} Response={"value":["TX0058_2","TX0058_5"]} Response={"value":{"TX0058_2":"A","TX0058_5":"D"]} As shown above. If the value 'Response' I get may be one of the above results, I want to further resolve the value of '[value]', what functions or methods can I use to distinguish them? Edited July 15, 2019 by Letraindusoir Link to comment Share on other sites More sharing options...
Developers Jos Posted July 15, 2019 Developers Share Posted July 15, 2019 2 hours ago, LukeWCS said: P.S.: Jos, are your recent changes stable so far that I can take over your latest version? Currently I am using the official version of the startup post. Aren't they the same? see the dates are. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted July 15, 2019 Developers Share Posted July 15, 2019 19 minutes ago, Letraindusoir said: what functions or methods can I use to distinguish them? No idea what the question is and the posted code isn't Autoit so please post something that is autoIt3 and supports your question. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now