0

I'm using P5.JS to attempt to display text from the MediaWiki API.

This is the api url im using https://en.wikipedia.org/w/api.php?action=parse&page=List_of_death_row_inmates_in_the_United_States&format=json&section=20&prop=text

I need the text which is at data.parse.wikitext.* However, when using the asterix, it throws an error stating "Unexpected token *". I've tried using quotation marks but no luck.

I'm able to display the object using data.parse.wikitext but cant access the specific text.

This same logic applies to this link: https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=Death_row where I am trying to get the extract text but I get an error when using JSON path queries.pages.20786828.extract because it doesn't like the integer.

Thanks

rexr
  • 89
  • 11

1 Answers1

1

You can use bracket notation to get the value at *:

data.parse.text['*']

This also works with keys that are numbers:

queries.pages['20786828'].extract
Andy
  • 61,948
  • 13
  • 68
  • 95