{"id":16884494,"url":"https://github.com/timwis/node-soda2-parser","last_synced_at":"2026-02-21T19:09:46.061Z","repository":{"id":35722239,"uuid":"40000446","full_name":"timwis/node-soda2-parser","owner":"timwis","description":"Parse Socrata SODA2 API to Abstract Syntax Tree (AST)","archived":false,"fork":false,"pushed_at":"2017-04-10T17:02:39.000Z","size":17,"stargazers_count":8,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T08:42:46.629Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timwis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-31T10:34:10.000Z","updated_at":"2019-08-18T16:49:03.000Z","dependencies_parsed_at":"2022-08-18T00:41:05.899Z","dependency_job_id":null,"html_url":"https://github.com/timwis/node-soda2-parser","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timwis%2Fnode-soda2-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timwis%2Fnode-soda2-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timwis%2Fnode-soda2-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timwis%2Fnode-soda2-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timwis","download_url":"https://codeload.github.com/timwis/node-soda2-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247968383,"owners_count":21025824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T16:28:35.788Z","updated_at":"2026-02-21T19:09:46.030Z","avatar_url":"https://github.com/timwis.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SODA2 Parser\nParse Socrata's [SODA2 API](http://dev.socrata.com/docs/queries.html) to [Abstract Syntax Tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (AST). This library is 99% [node-sqlparser](https://github.com/alibaba/nquery) and 1% SODA2 to SQL with SODA2 unit tests.\n\n# Usage\n\n```javascript\nvar Parser = require('node-soda2-parser');\nvar ast = Parser.parse(\"$select=date, type, magnitude\u0026$where=magnitude \u003e 3.0 and source = 'pr'\u0026$group=type\");\n```\n\n#### Parses to:\n\n```javascript\n{ type: 'select',\n  distinct: null,\n  columns:\n   [ { expr: { type: 'column_ref', table: '', column: 'date' },\n       as: null },\n     { expr: { type: 'column_ref', table: '', column: 'type' },\n       as: null },\n     { expr: { type: 'column_ref', table: '', column: 'magnitude' },\n       as: null } ],\n  from: null,\n  where:\n   { type: 'binary_expr',\n     operator: 'AND',\n     left:\n      { type: 'binary_expr',\n        operator: '\u003e',\n        left: { type: 'column_ref', table: '', column: 'magnitude' },\n        right: { type: 'number', value: 3 } },\n     right:\n      { type: 'binary_expr',\n        operator: '=',\n        left: { type: 'column_ref', table: '', column: 'source' },\n        right: { type: 'string', value: 'pr' } } },\n  groupby: [ { type: 'column_ref', table: '', column: 'type' } ],\n  orderby: null,\n  limit: null,\n  params: [] }\n```\nWith this AST, you can:\n\n- Convert it to clean SQL using `Parser.stringify.parse(ast)` (as seen in [soda-postgres](https://github.com/timwis/soda-postgres))\n- Write recursive functions to translate it to another query language\n- Write recursive functions to interact with an ORM\n- Print it out and hang it on the wall\n\n## Supported\nUnit tests in `test/soda` ensure the following functionality from the [SODA2 docs](http://dev.socrata.com/docs/queries.html) (which is basically everything except what's listed under Unsupported)\n### $select\n- Multiple fields\n- Field aliases\n- Functions, ie. `$select=date_trunc_ym(datetime) AS month`\n- Operators, ie. `$select=depth * 3.28 AS depth_feet`\n\n### $where\n- Basic filters, ie. `foo=bar\u0026animal=lion`\n- Expressions\n- Recursive And/Or\n- Functions, ie. `$where=within_box(incident_location, 47.5998951, -122.33707, 47.5942794, -122.3270522)`\n- Between, ie. `$where=date between '2015-01-10T12:00:00' and '2015-01-10T14:00:00'`\n- Operators, ie. `$where=end - start \u003c 1`\n- Modulo, ie. `$where=foo % 2`\n\n### Other\n- $group\n- $order\n- $limit\n- $offset\n\n## Unsupported\nThe following was tested and does not parse\n\n- **Not** between, ie. `$where=date not between '2015-01-10T12:00:00' and '2015-01-10T14:00:00'` ([reference](http://dev.socrata.com/docs/functions/not_between.html))\n- Escaping single quote by doubling, ie. `$where=text_value='Bob''s string'` ([reference](http://dev.socrata.com/docs/datatypes/text.html))\n- Double pipe concatenate, ie. `$select=theft_date, dc_dist || dc_num AS dist_dc` ([reference](http://dev.socrata.com/docs/datatypes/text.html))\n- Free text search, ie. `$q=foobar` ([reference](http://dev.socrata.com/docs/queries.html#search-with-q)) ([see issue](https://github.com/timwis/node-soda2-parser/issues/1))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimwis%2Fnode-soda2-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimwis%2Fnode-soda2-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimwis%2Fnode-soda2-parser/lists"}