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

100
Vistas
Trying a create a object using jsonata from existing object

Trying to create object out of existing object using jsonata. When the data and expression is put in jsonata excerciser, correct result is generated. However when I run it in Javascript program, errors are generated.

following is javascript code

const data = {
    "compCode": "0006",
    "compState": "MH",
    "recvDocNo": "0075",
    "buCode": "AC",
    "branchCode": "001",
    "recvLines": [
        {
            "lineNo": 1,
            "itemId": "00002",
            "qtyAccept": 10,
            "unitRate": 100,
            "basicVal": 1000,
            "taxableAmt": 1000,
        }
    ]
};

let expr = {
    "compCode": compCode,
    "buCode": buCode,
    "lineNo": recvLines.lineNo,
    "itemId": recvLines.itemId
};

jsonata(expr).evaluate(data);

I get error - ReferenceError: compCode is not defined

when I change it to data.compCode and all other object properties similarly, I get an error TypeError: path.charAt is not a function. Could someone tell me how to get it working. Thanks in advance

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

0

It looks like jsonata() expects a string expression as a parameter, which isn't explicitly stated in the docs, but is shown in the In Nodejs section.

const data = {
    "compCode": "0006",
    "compState": "MH",
    "recvDocNo": "0075",
    "buCode": "AC",
    "branchCode": "001",
    "recvLines": [
        {
            "lineNo": 1,
            "itemId": "00002",
            "qtyAccept": 10,
            "unitRate": 100,
            "basicVal": 1000,
            "taxableAmt": 1000,
        },
         {
            "lineNo": 2,
            "itemId": "00006",
            "qtyAccept": 10,
            "unitRate": 100,
            "basicVal": 1000,
            "taxableAmt": 1000,
        }
    ]
};

let expr = `{
  "compCode": compCode, 
  "buCode": buCode, 
  "lineNo": recvLines.lineNo, 
  "itemId": recvLines.itemId
  }`;

console.log(jsonata(expr).evaluate(data));
<script src="https://cdn.jsdelivr.net/npm/jsonata@1.8.5/jsonata.min.js"></script>

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