Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!