This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Better JSON access?

0

Surely there's got to be a better way to dump out the JSON text that this?

...Stu

do
    local json_fe = Field.new("json")
local tap = Listener.new("http", "http.content_type contains \"json\"")

function decode(c) return string.char(tonumber(c, 16)) end

function tap.reset() end

function tap.packet(pinfo, tvb, ip) local json = json_fe()

-- The extra ()s in the next line is to discard the second returned value from gsub
-- We only want to output the json object
print((tostring(json.value):gsub("(%x%x)", decode)))

end

function tap.draw() end

end

asked 08 Dec ‘11, 00:51

studog's gravatar image

studog
16224
accept rate: 0%

edited 08 Dec ‘11, 00:52


One Answer:

1

There you go:

function tap.packet(pinfo, tvb, ip)
  local json = json_fe();
  if (json ~= nil) then
    local tvbrange = json.range;
    local json_string = tvbrange:string();
  end
end

I think I've wasted some 2 days over this... issue. Jacek

answered 08 Sep '14, 00:47

Jacek's gravatar image

Jacek
161
accept rate: 0%