How to get JSON data for randomized game perks

JSON link: https://dbd.tricky.lol/api/randomperks?role=survivor

I have: $(eval const a=$(urlfetch json LINK); a[0].name;)
gives me: Cannot read properties of undefined (reading ‘name’)

$(eval const a=$(urlfetch json LINK is for sure getting the data

for example:

$(eval const a=$(urlfetch json https://dbd.tricky.lol/api/randomperks?role=survivor); let s = JSON.stringify(a).slice(0, 2); s)

is returning

{"

Data:

{“Resilience”:{“categories”:[“navigation”,“safeguard”,“strategy”],“name”:“Resilience”,“description”:“You are motivated in dire situations. Grants {0}% additional speed when repairing, sabotaging, healing, unhooking, vaulting, cleansing or blessing a Totem, opening exit gates, and unlocking while injured.”,“role”:“survivor”,“character”:null,“tunables”:[[“3”,“6”,“9”]],“modifier”:“Resilience”,“teachable”:0,“image”:“UI/Icons/Perks/iconPerks_resilience.png”},“S34P01”:{“categories”:null,“name”:“Potential Energy”,“description”:“Your arcane abilities have adapted to The Entity’s Realm after centuries of wandering, granting you unprecedented control over its many devices.

After working on a generator for {0} uninterrupted seconds, press the Active Ability Button 2 to activate this perk. When this perk is active, repairing the generator will charge this perk instead of making the generator progress. For each 1.5% of generator repair, the perk will gain 1 token, up to {1} tokens.

While this perk has at least one token and you are working on a generator, you can press the Active Ability Button 2 to consume all the tokens and instantly make the generator progress by 1% for each token. This perk then deactivates.

If you lose a health state while this perk has at least {3} token, the perk will lose all tokens and deactivate. Missing a Skill Check will also result in some tokens lost.”,“role”:“survivor”,“character”:33,“tunables”:[[“12”,“10”,“8”],[“20”],[“1”],[“1”]],“modifier”:“BP_S34P01”,“teachable”:30,“image”:“UI/Icons/Perks/Quantum/iconPerks_PotentialEnergy.png”},“BorrowedTime”:{“categories”:[“safeguard”],“name”:“Borrowed Time”,“description”:“You are fueled by unexpected energy when saving an ally from a hook.

Survivors you unhook:

  • Keep their Endurance status effect for an extra {0} seconds.
  • Keep their movement speed bonus for an extra 10 seconds.


  • Endurance prevents a Survivor from being downed, inflicting Deep Wound instead.

    Deep Wound will put a Survivor in the dying state unless it is mended before the timer runs out.”,“role”:“survivor”,“character”:7,“tunables”:[[“6”,“8”,“10”]],“modifier”:“BorrowedTime”,“teachable”:35,“image”:“UI/Icons/Perks/L4D/iconPerks_borrowedTime.png”},“Ace_In_The_Hole”:{“categories”:[“support”],“name”:“Ace in the Hole”,“description”:“Lady Luck always seems to be throwing something good your way.

    When retrieving an item from a chest, there is a {0}% chance that a Very Rare (or lower) add-on will be attached to it.

    {1}% chance of finding an add-on of Uncommon rarity (or lower).

    When escaping, keep any add-ons your item has.”,“role”:“survivor”,“character”:6,“tunables”:[[“100”],[“10”,“25”,“50”]],“modifier”:“AceInTheHole”,“teachable”:40,“image”:“UI/Icons/Perks/DLC3/iconPerks_aceInTheHole.png”}}

    @notyx01 Getting data from JSON is lot easier. Assuming you are getting “name” from the first object

    Your link is returning :-

    {
    	"SoleSurvivor": {
    		"categories": ["concealment"],
    		"name": "Sole Survivor",
    		"description": "As more of your friends fall to the Killer, you become shrouded in isolation and the Killer's <b>aura-reading abilities</b> towards you are disrupted.<br><br>Every time a fellow Survivor is killed or sacrificed, gain a token. For each token, your aura cannot be read by The Killer within a max range of {0} meters.<br><br>When you're the last Survivor alive:<li>Gain 75% action speed when repairing generators.</li><li>Gain 50% action speed while opening an exit gate or the Hatch.</li><br><br>Increases your chances of being The Killer's Obsession.<br><br>The Killer can only be <b>obsessed</b> with one Survivor at a time.",
    		"role": "survivor",
    		"character": 5,
    		"tunables": [
    			["20", "22", "24"]
    		],
    		"modifier": "SoleSurvivor_BP",
    		"teachable": 30,
    		"image": "UI/Icons/Perks/DLC2/iconPerks_soleSurvivor.png"
    	},
    ...
    

    Suppose you want to get the “name” from first element of the object

    $(eval 
        const object=$(urlfetch json https://dbd.tricky.lol/api/randomperks?role=survivor);  /* get the json data */
        for (let key in object) {
            key + " -> " + object[key]["name"];
            break;
        }
    )
    

    Here’s one line code:

    $(eval const object=$(urlfetch json https://dbd.tricky.lol/api/randomperks?role=survivor); for (let key in object) { key + " -> " + object[key]["name"]; break; })
    

    Hope that helps

    Regards

    This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.