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

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


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

permanent link

answered 08 Sep '14, 00:47

Jacek's gravatar image

Jacek
161
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×431
×9

question asked: 08 Dec '11, 00:51

question was seen: 6,134 times

last updated: 08 Sep '14, 00:47

p​o​w​e​r​e​d by O​S​Q​A