PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 24, 2022

[FIXED] How to get object name when it contains DOTs, CURLY BRACES and HASHTAGs on JSONPath?

 July 24, 2022     json, jsonpath, regex, zabbix     No comments   

Issue

I have the following JSON structure, generated by Zabbix Discovery key, with the following data:

[{
    "{#SERVICE.NAME}": ".WindowsService1",
    "{#SERVICE.DISPLAYNAME}": ".WindowsService1 - Testing",
    "{#SERVICE.DESCRIPTION}": "Application Test 1 - Master",
    "{#SERVICE.STATE}": 0,
    "{#SERVICE.STATENAME}": "running",
    "{#SERVICE.PATH}": "E:\\App\\Test\\bin\\testingApp.exe",
    "{#SERVICE.USER}": "LocalSystem",
    "{#SERVICE.STARTUPTRIGGER}": 0,
    "{#SERVICE.STARTUP}": 1,
    "{#SERVICE.STARTUPNAME}": "automatic delayed"
},
{
    "{#SERVICE.NAME}": ".WindowsService2",
    "{#SERVICE.DISPLAYNAME}": ".WindowsService2 - Testing",
    "{#SERVICE.DESCRIPTION}": "Application Test 2 - Slave",
    "{#SERVICE.STATE}": 0,
    "{#SERVICE.STATENAME}": "running",
    "{#SERVICE.PATH}": "E:\\App\\Test\\bin\\testingApp.exe",
    "{#SERVICE.USER}": "LocalSystem",
    "{#SERVICE.STARTUPTRIGGER}": 0,
    "{#SERVICE.STARTUP}": 1,
    "{#SERVICE.STARTUPNAME}": "automatic delayed"
}]

So, what i want to do is: Use JSONPath to get ONLY the object that {#SERVICE.NAME} == WindowsService1...

The problem is, i am trying to create the JSONPath but it's giving me a couple of errors. Here's what i tried, and what i discovered so far:

JSONPath:

$.[?(@.{#SERVICE.NAME} == '.WindowsService1')]

Error output:

jsonPath: Unexpected token '{': _$_v.{#SERVICE.NAME} == '.WindowsService1'

I also tried doing the following JSONPath, to match Regular Expression:

$.[?(@.{#SERVICE.NAME} =~ '^(.WindowsService1$)')]

It gave me the same error - So the problem is not after the == or =~ ... What i discovered is, if i REMOVE the curly braces {}, the hashtag # and replace the dot . in "Service name" with _ (Underline), in JSONPath and in JSON data, it works, like this:

Data without # {} . :

 [{
        "SERVICE_NAME": ".WindowsService1",
[...]

JSONPath following new data structure:

$.[?(@.SERVICE_NAME == '.WindowsService1')]

But the real problem is, i need to maintain the original strucutre, with the curly braces, dots, and hashtags...

How can i escape those and stop seeing this error? Thank you...


Solution

$.[?(@['{#SERVICE.NAME}'] == '.WindowsService1')]



Answered By - Raul Chiarella
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing