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

270
Views
How to use multiple if else conditions using ternary operator in jsonpath- plus?

JSON

{
   "customer":{
      "address":{
         "stateRegion":"",
         "stateRegionCode":""
      }
   }
}

Code

"address.state_code": "$.customer.address.[stateRegion ? stateRegion: stateRegionCode?stateRegionCode: null]",

Here in the above expression , I want stateRegion as the value if it is present in customer as parent object and address as a child object , else I want stateRegionCode and if both are not present I want null, how can we customize this thing using jsonpath-plus?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can't do this during the initial creation of the object because accessing the object's properties (for use in your conditional expression) requires that the object already exists.

Maybe the closest you can get is, once you've defined the object, to write something similar to your "address.state_code": "$.customer.address.[stateRegion ? stateRegion: stateRegionCode?stateRegionCode: null]":

const
  $ = { "customer" : { "address" : { "stateRegion" : "", "stateRegionCode" : "" } } },
  {stateRegion, stateRegionCode} = $.customer.address; // Destructures address
$.customer.address.state_code = stateRegion
  ? stateRegion
  : stateRegionCode
    ? stateRegionCode
    : null;

console.log($.customer.address);

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!