0

I am struggling to collect data from a nested list. The list looks something like this

http://jsfiddle.net/Sullan/k7vSg/1/

From this list I am trying to create a JSON result which is similar to this

{
   "coreservices":[
      {
         "title":"Review",
         "review":"Quaterly",
         "scheduled":[
            {
               "date1":"February",
               "date2":"February 11"
            },
            {
               "date1":"August",
               "date2":"August 6"
            }
         ]
      },
      {
         "title":"Analysis",
         "review":"Semi-Annually",
         "scheduled":[
            {
               "date1":"March",
               "date2":"March 22"
            },
            {
               "date1":"May",
               "date2":"May 10"
            }
         ]
      }
   ],
   "functions":[
      {
         "title":"Communication",
         "review":"Semi-Annually",
         "scheduled":[
            {
               "date1":"February",
               "date2":"February 11"
            },
            {
               "date1":"August",
               "date2":"August 6"
            }
         ]
      },
      {
         "title":"Meeting",
         "review":"Semi-Annually",
         "scheduled":[
            {
               "date1":"March",
               "date2":"March 22"
            },
            {
               "date1":"May",
               "date2":"May 10"
            }
         ]
      }
   ]
}

It would be of great help if anybody direct me on how to achieve this. Thanks in advance

2
  • You want to scrape the HTML to generate the data? Commented Feb 23, 2012 at 15:27
  • @Diodeus No, I want to extract the data as json from the html. I have added some sorting, and dynamic additions to the list, based on that i have to generate the new json output to send it to the server. Commented Feb 23, 2012 at 16:25

1 Answer 1

4

Please try the following jsfiddle to see if it brings you close to what you need: http://jsfiddle.net/k7vSg/2/

It's quick and dirty, but I'm hoping it'll help you.

Cheers, iso

Sign up to request clarification or add additional context in comments.

2 Comments

awesome, worked like a charm. I am damn sure i could not have done this on my own. thanks a lot, so this mean I go home early today :-)
My pleasure. If ever you have control over how they come out originally, it would be easier if you added classes to your spans. You wouldn't need to count them out for the splitting of the dates, for instance. Also, if ever you're sending via AJAX, you could simply send the "everything" object (without needing to convert to JSON). Enjoy your night off ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.