Adobe Lightroom Catalog API returns code+JSON

150 views Asked by At

When using the Adobe Lightroom Catalog API to access the catalogs in a Lightroom account, the resulting data is a combination of code and JSON starting with:

while (1) {}\n{\"base\":\"https://lr.adobe.io/v2/\",\"id\":\"7afe....

This is different from the documentation which only specifies the JSON.

  1. Can I safely trim the "while (1) {} at the beginning

  2. Should I modify my request

  3. Should I do other changes to GET response string as well?

1

There are 1 answers

0
Asgeir Enersen On

Yes, you can safely trim off the while (1) {} part.

It is simply a security measure to prevent automatic execution of malicious code hidden inside the json structure.

Unfortunately, this can make your code more complicated. Instead of a simple

const data = await fetch('https://lr.adobe.io/v2')
    .then((response) => response.json());

you must do something like this:

const data = await fetch('https://lr.adobe.io/v2')
    .then((response) => response.text())
    .then((text) => text.replace('while (1) {}', ''))
    .then((json) => JSON.parse(json.trim()));