Retrieve online JSON data

Hello,
I would like to retrieve some online JSON data, and I dont manage.
first, I cannont print the row data ;
then, what are the equivalents of getJSONObject and getJSONArray from Processing ?
Indeed I have to go at this path facet_counts>facet_fields

var jsonData;

function preload() {
	var codeLab = '15218';
	var url = 'https://api.archives-ouvertes.fr/search/?q=*:*&rows=0&facet=true&facet.field=structHasAuthIdHal_fs&facet.prefix=' +
		codeLab + '_&wt=json&facet.limit=30';
	jsonData = loadJSON(url);
}

function setup() {
	noLoop();
}

function draw() {
	print(jsonData); // return only [object Object]
        // go to this array :  to facet_counts>facet_fields position>structHasAuthIdHal_fs
}

my goal is to translate this Processing sketch.
thanks.

Some online JSON sketches I’ve got for p5.js: :cowboy_hat_face:

  1. Bl.ocks.org/GoSubRoutine/5fbc03e019c53254a2ba7e7fd3318b45
  2. Bl.ocks.org/GoSubRoutine/7a567f0510b338b6d0fc1ef53f24f10e
  3. Bl.ocks.org/GoSubRoutine/9aa9cd00000e331612c8e557b5dd28f0

https://api.Archives-Ouvertes.fr/search/?q=:&rows=0&facet=true&facet.field=structHasAuthIdHal_fs&facet.prefix=_&wt=json&facet.limit=30

{
  "response": {
    "numFound": 1608268,
    "start": 0,
    "docs": []
  },
  "facet_counts": {
    "facet_queries": {},
    "facet_fields": {
      "structHasAuthIdHal_fs": []
    },
    "facet_ranges": {},
    "facet_intervals": {},
    "facet_heatmaps": {}
  }
}
1 Like
  1. getJSONObject(): use the dot . accessor operator, followed by the name of the property:
    const num = jsonObj.response.numFound;
  2. getJSONArray(): use the brackets [] accessor operator, plus the desired index:
    const gotId4 = jsonObj.facet_counts.facet_fields.structHasAuthIdHal_fs[3];
1 Like

this was because I used the openprocessing.org online eitor ; now it works fine with local files.

no pb for the dot and brackets accessor : thanks.