SQL is the API for data.
But for nested data (XML, JSON, etc.) it really isn't the best language for that. I am talking here specifically about not querying data that is nested, but actually getting query results in a nested format. SQL can do it (almost all major databases have XML and JSON support) but it rally isn't the easiest thing to use.
We should also consider the capabilities of PostgreSQL to query JSON documents.