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

271
Vistas
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 Respuestas
Responde la pregunta

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 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