It is currently March 9th, 2021, 11:31 am

Help needed querying JSON without elements

Help with creating, editing & fixing problems with skins
User avatar
Eldiablotoro
Posts: 2
Joined: February 17th, 2021, 2:54 am

Help needed querying JSON without elements

Post by Eldiablotoro »

Hi all,

I'm just starting to write my first skin and I am having trouble querying a json file. I am currently using the plugins WebParser and JsonParser.

JSON: http://ddragon.leagueoflegends.com/cdn/11.3.1/data/en_US/champion.json

I am trying to retrieve the "id" property value with a supplied "key" value. So for example, I have the # "266" and I want the query to return the "id" property which has the value "Aatrox".

Here is my code so far:

Code: Select all

[MeasureGetAllChampions]
Measure=Plugin
Plugin=WebParser
URL="http://ddragon.leagueoflegends.com/cdn/11.3.1/data/en_US/champion.json"
RegExp=(?siU)^(.*)$

[MeasureGetSpecificChampion]
Measure=Plugin
Plugin=JsonParser.dll
Source=[MeasureGetAllChampions]
;Query="$.data.Aatrox.id" ;This gets the needed ID but I don't actually know how to get the ID without knowing its parent.
;Query="$.data[?(@.key == 266)].id" ;This is not possible because each champion name is a property, not an element.
Snippet of champion.json. Notice how "data" is not an array...:

Code: Select all

{
    "type": "champion",
    "format": "standAloneComplex",
    "version": "11.3.1",
    "data": {
        "Aatrox": {
            "version": "11.3.1",
            "id": "Aatrox",
            "key": "266",
            ...
        },
        "Ahri": {
            "version": "11.3.1",
            "id": "Ahri",
            "key": "103",
            ...
        },
        "Akali": {
            "version": "11.3.1",
            "id": "Akali",
            "key": "84",
            ...
        },
        ...
    }
}
I'm not sure if I'm not being creative enough with the JSON, or if there is another plugin/Lua that is recommended. Thanks.
Last edited by Eldiablotoro on February 17th, 2021, 4:36 pm, edited 1 time in total.
User avatar
Eldiablotoro
Posts: 2
Joined: February 17th, 2021, 2:54 am

Re: Help needed querying JSON without elements

Post by Eldiablotoro »

UPDATE: I was able to solve this issue after a night's rest. Here was my solution:

I went back to the WebParser/RegExp. The original reason for abandoning it in favor of the JsonParser was because I would pull unwanted characters/data using the (.*) wildcard. I went back to it to try to add a "filter" on the wildcard. Here is the final implementation:

Code: Select all

[MeasureGetSpecificChampion]
Measure=Plugin
Plugin=WebParser
URL="http://ddragon.leagueoflegends.com/cdn/11.3.1/data/en_US/champion.json"
RegExp=(?siU):{"version":"11.3.1","id":"([a-zA-Z]*)","key":"266",
StringIndex=1