Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
Can't #include in illustrator script code

I am trying to read a JSON file, in order to make changes in an illustrator document according to the data in that JSON file.

I tried this code:

#include 'libs/json2.js';
    
function readJSONFile(file) {

  file.open("r");
  var data = file.read();
  file.close();
  data = JSON.parse(data);
  for(var i in data) {
    $.writeln(i + "=" + data[i]);
  }
}
function getCorrections()
{
  const corrections = readJSONFile(File('C:/corrections.json'));
  alert(corrections);
}

getCorrections();

but when I run the script in Illustrator, it gives me an error saying "JSON is undefined"

so, I tried to use #import as I've seen in other Stackoverflow threads, but it seems like Illustrator don't accept that syntax.

#include 'libs/json2.js';

I get this error:

Error 23: ) does not not have a value.
Line: 1
-> ()

I would be glad to get some help importing an external library to my script, thank you.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this:

// @include 'libs/json2.js'

But actually both of the variants work for me. #includes is a valid option for Illustrator.

Perhaps the problem is in your data. I could try to parse it if you provide the sample of your date.

Here is full code that works for me:

#include 'libs/json2.js';

var file = File('d:/stackoverflow/jsx/json/test.json'); // <-- a full path!!!
readJSONFile(file);

function readJSONFile(file) {
    file.open("r");
    var data = file.read();
    file.close();
    data = JSON.parse(data);
    for (var i in data) {
        $.writeln(i + "=" + data[i]);
    }
}

test.json file:

{
    "patches": [
        {
            "patchName": "N0",
            "offsetL": "1",
            "offsetA": "-1",
            "offsetB": "2"
        },
        {
            "patchName": "N1",
            "offsetL": "1",
            "offsetA": "-1",
            "offsetB": "2"
        }
    ]
}

Everything works fine:

enter image description here

Check the path to your json file.

You can get the folder that contains a current script this way:

var script_folder = File($.fileName).parent;

alert(script_folder); // 'd/stackoverflow/jsx/json' in my case
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda