Nmap Development mailing list archives

Re: Parsing JSON


From: Daniel Miller <bonsaiviking () gmail com>
Date: Mon, 6 Feb 2017 12:57:26 -0600

David,

I just missed you in IRC. I don't see any problem with parsing this with
json.lua. To get the rendered title, I would use this:

local status, parsed = json.parse('[{"id":1,...')
title = parsed[1].title.rendered

Note that your data is wrapped in a single-element array, and Lua uses
1-indexed tables as arrays. So the first element is index 1, and "title" is
a key in the object at that index.

Dan

On Mon, Feb 6, 2017 at 7:21 AM, David Muscut <davidmuscut () gmail com> wrote:

Can someone point me to a code example of how I can parse out the 'id'
and 'title' values using the Nmap json.lua library for the following code:

[{"id":1,"date":"2017-02-05T13:02:28","date_gmt":"2017-02-05T13:02:28","guid":{"rendered":"http:\/\/localhost\/wp2\/wordpress\/?p=1"},"modified":"2017-02-05T13:02:28","modified_gmt":"2017-02-05T13:02:28","slug":"hello-world","type":"post","link":"http:\/\/localhost\/wp2\/wordpress\/2017\/02\/05\/hello-world\/","title":{"rendered":"Hello
 world!"},"content":{"rendered":"<p>Welcome to WordPress. This is your first post. Edit or delete it, then start 
writing!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to WordPress. This is your first post. Edit or 
delete it, then start 
writing!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/localhost\/wp2\/wordpress\/wp-json\/wp\/v2\/posts\/1"}],"collection":[{"href":"http:\/\/localhost\/wp2\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/localhost\/wp2\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/localhost\/wp2\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/localhost\/wp2\/wordpress\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"href":"http:\/\/localhost\/wp2\/wordpress\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"wp:attachment":[{"href":"http:\/\/localhost\/wp2\/wordpress\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost\/wp2\/wordpress\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost\/wp2\/wordpress\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}]

thanks!

-D


_______________________________________________
Sent through the dev mailing list
https://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/

_______________________________________________
Sent through the dev mailing list
https://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/

Current thread: