• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

JSONPATH

I have the following JSON structure:

{ "identification" : "AlphaBeta" }

Open in new window


What I want to do is write a conditional that states something like (In Pseudo code)

  IF identification = 'Alpha*'
     TRUE
  ELSE 
     FALSE

Open in new window


Therefore the function above would return true if
'identification' was equal to any of the three values below

AlphaGraphics
AlphaCentauri
AlphaBeta

Open in new window


But would return false if 'identification' is equal to the following value:

AlaskaBeta

Open in new window


How do I convert the pseudo code above to JSONPATH ?

What would that look like in JSONPATH ?

Thanks
0
Anthony Lucia
Asked:
Anthony Lucia
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
function checkIdent(j) {
    return j.identification.indexOf("Alpha") == 0;
}

var j = { "identification" : "AlphaBeta" };
// USE :
alert( checkIdent( j ) ); // alert true or false (in our case true)

Open in new window

0
 
leakim971PluritechnicianCommented:
test page : http://jsfiddle.net/SEjH2/

function checkIdent(j) {
    return j.identification.indexOf("Alpha") == 0;
}

// TRUE
var j = { "identification" : "AlphaBeta" };
alert( checkIdent(j) );

//  FALSE
var k = { "identification"  : "AlaskaBeta" };
alert( checkIdent(k) );

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now