I'm trying to use classes and a json file instead of just a big set of
nested hashes. The desired end state is a json file that I can load,
update, and use to track vulnerabilities. When I look at the file now it's
just the object ids, I think, which will not be the same if I use a
different script to load the data.
https://gist.github.com/LeamHall/a42236a4b6a9eac44669
What am I missing? Is an array of objects the way to handle this?
Thanks!
Leam
···
--
Mind on a Mission <http://leamhall.blogspot.com/>
What about using YAML Store instead?
···
On 05/15/2015 13:32:58, leam hall wrote:
I'm trying to use classes and a json file instead of just a big set of
nested hashes. The desired end state is a json file that I can load,
update, and use to track vulnerabilities. When I look at the file now it's
just the object ids, I think, which will not be the same if I use a
different script to load the data.
https://gist.github.com/LeamHall/a42236a4b6a9eac44669
What am I missing? Is an array of objects the way to handle this?
Thanks!
Leam
--
Mind on a Mission <http://leamhall.blogspot.com/>
--
Raj Sahae
408.230.8531
I'm trying to move to MongoDB at some point in time, hence the JSON.
Leam
···
On Fri, May 15, 2015 at 3:07 PM, Raj Sahae <rajsahae@gmail.com> wrote:
What about using YAML Store instead?
--
Mind on a Mission <http://leamhall.blogspot.com/>
You need to implement the to_json method for you custom class. Check
this answer from stackoverflow:
So, add something like this in your class:
class Vuln
attr_accessor :vid, :task, :title
def initialize(vid, task, title)
@vid = vid
@task = task
@title = title
end
def to_json *a
{"vid" =>@vid, "task"=>@task, "title"=>@title}.to_json(*a)
end
end
Then you can do:
[Vuln.new(1234, 'audit', "Some thing or other."), Vuln.new(2345,
'audit', "Some other thing or other.")].to_json
=> "[{\"vid\":1234,\"task\":\"audit\",\"title\":\"Some thing or
other.\"},{\"vid\":2345,\"task\":\"audit\",\"title\":\"Some other
thing or other.\"}]"
Hope this helps,
Jesus.
···
On Fri, May 15, 2015 at 7:32 PM, leam hall <leamhall@gmail.com> wrote:
I'm trying to use classes and a json file instead of just a big set of
nested hashes. The desired end state is a json file that I can load, update,
and use to track vulnerabilities. When I look at the file now it's just the
object ids, I think, which will not be the same if I use a different script
to load the data.
https://gist.github.com/LeamHall/a42236a4b6a9eac44669
What am I missing? Is an array of objects the way to handle this?
Thanks!
Leam
--
Mind on a Mission