Nmap Development mailing list archives
Re: Parsing JSON
From: Daniel Miller <bonsaiviking () gmail com>
Date: Mon, 6 Feb 2017 22:17:39 -0600
David, I saw that; the documentation for the json.lua library had not been updated since we changed its tests to those that use unittest.lua, so I removed it. Instead, you can use the nsedebug.tostr [1] function to see the structure that was parsed. Dan [1] https://nmap.org/nsedoc/lib/nsedebug.html#tostr On Mon, Feb 6, 2017 at 2:23 PM, David Muscut <davidmuscut () gmail com> wrote:
Thanks Dan. A follow up question, the json.lua documentation says "If you want to parse JSON, you can test it by pasting sample JSON into the TESTS table and run the test method". Can you show an example of how you run "the test method"? thanks, - D On Mon, Feb 6, 2017 at 8:57 PM, Daniel Miller <bonsaiviking () gmail com> wrote: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:
- Parsing JSON David Muscut (Feb 06)
- Re: Parsing JSON Daniel Miller (Feb 06)
- Re: Parsing JSON David Muscut (Feb 06)
- Re: Parsing JSON Daniel Miller (Feb 06)
- Re: Parsing JSON David Muscut (Feb 06)
- Re: Parsing JSON Daniel Miller (Feb 06)