RAMzor Posted August 6 Share Posted August 6 (edited) Hello all, I have such JSON file (the example is simplified for demonstration, the original one can content about 20000 array blocks or even more). I need the audience help to flip the "Flip_Me" array. expandcollapse popup{ "Example": { "EnableList": true, "Color": true "Flip_Me": [ { "Name": "Test_1", "Type": { "CAT": 1.1, "DOG": 1.2, "FOX": 1.3 }, "Form": { "ABC": 1.4, "CDE": 1.5, "NON": 1.6 } }, { "Name": "Test_2", "Type": { "CAT": 2.1, "DOG": 2.2, "FOX": 2.3 }, "Form": { "ABC": 2.4, "CDE": 2.5, "NON": 2.6 } }, { "Name": "Test_3", "Type": { "CAT": 3.1, "DOG": 3.2, "FOX": 3.3 }, "Form": { "ABC": 3.4, "CDE": 3.5, "NON": 3.6 } } ] } } Thanks Edited August 6 by RAMzor Link to comment Share on other sites More sharing options...
Solution TheXman Posted August 6 Solution Share Posted August 6 (edited) Your JSON has an error. There should be a comma after "Color": true I'm not sure what you mean by "flip" the array. If you mean reverse the entries in the array, then using jq you can do something like this: #include <Constants.au3> #include <jq\jq.au3> jq_example() Func jq_example() Const $JSON_DATA = '{"Example":{"EnableList":true,"Color":true,"Flip_Me":[{"Name":"Test_1","Type":{"CAT":1.1,"DOG":1.2,"FOX":1.3},"Form":{"ABC":1.4,"CDE":1.5,"NON":1.6}},{"Name":"Test_2","Type":{"CAT":2.1,"DOG":2.2,"FOX":2.3},"Form":{"ABC":2.4,"CDE":2.5,"NON":2.6}},{"Name":"Test_3","Type":{"CAT":3.1,"DOG":3.2,"FOX":3.3},"Form":{"ABC":3.4,"CDE":3.5,"NON":3.6}}]}}' Local $sResult Local $hTimer = TimerInit() ;Identify path to exe _jqInit("C:\Utils\JQ\jq-win64.exe") If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "jqInit() Error", "Unable to find jq executable - @error = " & @error) ;Process JSON dataset $sResult = _jqExec($JSON_DATA, ".Example.Flip_Me = (.Example.Flip_Me|reverse)") ;Display result ConsoleWrite(StringFormat('Time to get result: %.3f seconds', TimerDiff($hTimer)/1000) & @CRLF) ConsoleWrite($sResult & @CRLF) EndFunc My result: expandcollapse popupTime to get result: 0.023 seconds { "Example": { "EnableList": true, "Color": true, "Flip_Me": [ { "Name": "Test_3", "Type": { "CAT": 3.1, "DOG": 3.2, "FOX": 3.3 }, "Form": { "ABC": 3.4, "CDE": 3.5, "NON": 3.6 } }, { "Name": "Test_2", "Type": { "CAT": 2.1, "DOG": 2.2, "FOX": 2.3 }, "Form": { "ABC": 2.4, "CDE": 2.5, "NON": 2.6 } }, { "Name": "Test_1", "Type": { "CAT": 1.1, "DOG": 1.2, "FOX": 1.3 }, "Form": { "ABC": 1.4, "CDE": 1.5, "NON": 1.6 } } ] } } In jqPlayground: Edited August 6 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...
RAMzor Posted August 7 Author Share Posted August 7 Many thanks for the answer! This is exactly what I was looking for. 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