Giter Site home page Giter Site logo

Comments (9)

Skarlso avatar Skarlso commented on August 16, 2024

@NDuggan So sorry, was bogged down with a ton of stuff! This is next on my todo list now though. :)

from jsonpath.

Skarlso avatar Skarlso commented on August 16, 2024

What... even is that? :D

from jsonpath.

Skarlso avatar Skarlso commented on August 16, 2024

Oh it's a regex match against an element. Or at least something like a "%http%" in SQL and the likes. Hmmmmmm.....

from jsonpath.

Skarlso avatar Skarlso commented on August 16, 2024

The parsing kind of completely falls apart on this one. :/ Uh.

from jsonpath.

Skarlso avatar Skarlso commented on August 16, 2024

Alright, so I might be able to handle this gracefully, I think. Your pattern in that case would be something like /http/.match(@whatever. I'm using match to conform to ruby's regex match.

from jsonpath.

khairihafsham avatar khairihafsham commented on August 16, 2024

I wonder if this syntax is a standard that should be adopted? there is no standard reference other than the original https://goessner.net/articles/JsonPath/ and even there makes no mention of filters supporting regex

Looking at the Java implementation to support regex filter is also different: https://github.com/json-path/JsonPath

from jsonpath.

Skarlso avatar Skarlso commented on August 16, 2024

Yah, that's why I was reluctant to do it. It sort of messes things up a bit. :/ But I might implement it at one point anyways. :)

from jsonpath.

Skarlso avatar Skarlso commented on August 16, 2024

@khairihafsham It just dawned on my that I'm supporting regex in a query.

You could try ?(@name =~ /http[s]?/) or something like that.

from jsonpath.

Skarlso avatar Skarlso commented on August 16, 2024

@khairihafsham Yep. This actually works:

  def test_regex_2
    json = '
    {
      "ports": {
        "extraports": {
          "count": "996",
          "state": "filtered",
          "extrareasons": {
            "count": "996",
            "reason": "no-responses"
          }
        },
        "port": [
          {
            "portid": "80",
            "protocol": "tcp",
            "service": {
              "conf": "3",
              "method": "table",
              "name": "http"
            },
            "state": {
              "reason": "syn-ack",
              "reason_ttl": "44",
              "state": "open"
            }
          },
          {
            "portid": "443",
            "protocol": "tcp",
            "service": {
              "conf": "3",
              "method": "table",
              "name": "https"
            },
            "state": {
              "reason": "syn-ack",
              "reason_ttl": "44",
              "state": "open"
            }
          },
          {
            "portid": "2222",
            "protocol": "tcp",
            "service": {
              "conf": "3",
              "method": "table",
              "name": "EtherNetIP-1"
            },
            "state": {
              "reason": "syn-ack",
              "reason_ttl": "45",
              "state": "open"
            }
          },
          {
            "portid": "3128",
            "protocol": "tcp",
            "service": {
              "conf": "3",
              "method": "table",
              "name": "squid-http"
            },
            "state": {
              "reason": "syn-ack",
              "reason_ttl": "44",
              "state": "open"
            }
          }
        ]
      }
    }
    '.to_json
    assert_equal [{"conf"=>"3", "method"=>"table", "name"=>"http"}, {"conf"=>"3", "method"=>"table", "name"=>"https"}, {"conf"=>"3", "method"=>"table", "name"=>"squid-http"}], JsonPath.on(json, "$..[?(@.name =~ /http[s]?/)]")
  end

from jsonpath.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.