JSON parser extractor name with a "-"

Reply
L1 Bithead

JSON parser extractor name with a "-"

I have a JSON list (URL https://ip-ranges.cloud.signiant.com/MediaShuttle) with one part of the JSON path name containing a minus sign ("-"):

 

{
    "us-east-1": {
        "all_ips": [
            "3.83.158.71", 
            "3.87.14.184", 
            "34.207.126.66", 
            "34.227.155.76", 
            "34.236.155.245", 
            "52.2.203.56", 
            "52.23.203.179", 
            "52.73.28.78", 
            "52.86.231.134"
        ]
    }
}

 

Using the  JMESPath tester from jmespath.org, I created an expression that pulls out what I need:

  

  us-east-1.all_ips

 

However, the Minemeld engine will not start, throwing an 'Unknown Character" error, apparently due to the dash.  I've tried escaping and quoting using several variations and I cannot create the extractor needed.  These are the variations I've tried:

 

  • us-east-1.all_ips: Unknown Character (the '-')
  • "us-east-1.all_ips": Unknown Character
  • "us-east-1".all_ips: Engine won't start
  • "us-east-1".all_ips[]: Engine won't start
  • 'us-east-1'.all_ips: engine won't start
  • 'us-east-1'.all_ips[].{indicator:@}: engine won't start
  • "us-east-1".all_ips[].{indicator:@}: engine won't start
  • us\-east\-1.all_ips[].{indicator:@}: Unknown character
  • "us-east-1.all_ips"[].{indicator:@}: engine won't start (expected end but found [)
  • "us-east-1.all_ips[]".{indicator:@}: expected <block end>, but found '<scalar>'
  • "us-east-1.all_ips[].{indicator:@}": Unknown character
  • "us\-east\-1.all_ips[].{indicator:@}": engine won't start

 

Thanks in advance,

 

Mike

L5 Sessionator

Re: JSON parser extractor name with a "-"

Hi @MichaelPDean,

 

this is a tricky one.

 

the right expression is already in your list (us-east-1.all_ips[].{indicator:@})  but it must be double escaped .

 

First, us-east-1 is not a valid python espression so you must quote it to become "us-east-1" . But you can't provide extractor: "us-east-1".all_ips[].{indicator:@} to the prototype because the YAML loader will fail parsing it due to the first double quote describing the value to be a string scalar and the dot character after the second double quote being considered as an invalid sequence.

 

So you must escape again for the YAML loader to consider the whole line a string scalar. The right value is then:

 

extractor: '"us-east-1".all_ips[].{indicator:@}'

 

 

L1 Bithead

Re: JSON parser extractor name with a "-"

Thanks, that worked!

Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the Live Community as a whole!

The Live Community thanks you for your participation!