Live data from Hacker News

The US Census now has an API

census.gov

1–10 of 42 posts

Re: The US Census now has an API

#5
> The response for all queries is formatted as a two dimensional JSON array where the first row provides column names and subsequent rows provide data values.

Hmmm... looking at the example of this I can't help but think there has got to be a better way. This is more just a standard CSV (first row is header, all other rows are data). Using JSON for data formatted as such is kind of a waste of JSON. If you pass that example into a JSON decoder you get an extremely more difficult to use object. Am I missing something? or is this just typical "the government doesn't do tech properly" stuff?

EDIT: sorry, I try to be less negative but sometimes it is hard. I do applaud them for at least making the info available. I don't have a use for it but if some else does then dealing with a stupid format is better than not having data at all.

EDIT2: (to clarify) I was not saying the data should just be CSV... I'm saying it is and that defeats the purpose of using JSON. They should still use JSON but with their data formatted differently. Using their example, properly closed but truncated to just to first 2 records, the PHP function json_decode() turns it into this array:

  array (
    0 => array (
      0 => 'P0010001',
      1 => 'NAME',
      2 => 'state',
    ),
    1 => array (
      0 => '710231',
      1 => 'Alaska',
      2 => '02',
    ),
    2 => array (
      0 => '4779736',
      1 => 'Alabama',
      2 => '01',
    ),
  )
I don't find that format to be very pleasant.

Re: The US Census now has an API

#7

> The response for all queries is formatted as a two dimensional JSON array where the first row provides column names and subsequent rows provide data values. Hmmm... looking at the example of this I can't help but think there has got to be a better way. This is more just a standard CSV (first row is header, all other rows are data). Using JSON for data formatted as such is kind of a waste of JSON. If you pass that e…

I also found this odd, but I can think of two reasons,

1. CSV is not a single well-defined format. Some people use rfc4180, but not everybody does.

2. JSON is easier to parse than CSV for JavaScript clients, i.e., browsers. On the other hand, JSON is not a subset of JavaScript.

Re: The US Census now has an API

#8

> The response for all queries is formatted as a two dimensional JSON array where the first row provides column names and subsequent rows provide data values. Hmmm... looking at the example of this I can't help but think there has got to be a better way. This is more just a standard CSV (first row is header, all other rows are data). Using JSON for data formatted as such is kind of a waste of JSON. If you pass that e…

It's very simple to transform that kind of data into $your_preferred_structure.

It's also a very agnostic format.

Re: The US Census now has an API

#10
Cool, especially since the census is one of the main reasons why we have computers at all.

I went to the Computer History Museum a few months back, and when we were looking through the origins of the modern computer, a lot of it traces back to census needs: we needed to automate the counting of large quantities of uniformly formatted data, so we used punchcards to tally up the data.

Fast forward to 2012, and the census is now getting an API. Weird how that works.

Post reply on HN