{"id":31530180,"url":"https://github.com/frictionlessdata/datapackage-java","last_synced_at":"2026-03-16T08:34:07.472Z","repository":{"id":41300914,"uuid":"92710246","full_name":"frictionlessdata/datapackage-java","owner":"frictionlessdata","description":"A Java library for working with Frictionless Data Data Packages.","archived":false,"fork":false,"pushed_at":"2025-10-02T14:40:25.000Z","size":7077,"stargazers_count":23,"open_issues_count":8,"forks_count":6,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-10-02T16:25:28.089Z","etag":null,"topics":["data-science","datapackage","datapackage-java","frictionlessdata","java","java-8","java8","json-schema"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frictionlessdata.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-05-29T05:43:00.000Z","updated_at":"2025-10-02T14:40:21.000Z","dependencies_parsed_at":"2025-07-07T08:34:41.548Z","dependency_job_id":"501532bb-24c8-4971-b4bb-203cd38ac269","html_url":"https://github.com/frictionlessdata/datapackage-java","commit_stats":{"total_commits":286,"total_committers":9,"mean_commits":31.77777777777778,"dds":"0.42307692307692313","last_synced_commit":"0369c359e095d9e08c5f96c662d44f445fc07ed8"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"purl":"pkg:github/frictionlessdata/datapackage-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Fdatapackage-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Fdatapackage-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Fdatapackage-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Fdatapackage-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frictionlessdata","download_url":"https://codeload.github.com/frictionlessdata/datapackage-java/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Fdatapackage-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278252187,"owners_count":25956258,"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","status":"online","status_checked_at":"2025-10-03T02:00:06.070Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["data-science","datapackage","datapackage-java","frictionlessdata","java","java-8","java8","json-schema"],"created_at":"2025-10-04T01:18:57.810Z","updated_at":"2025-10-04T01:19:11.626Z","avatar_url":"https://github.com/frictionlessdata.png","language":"Java","readme":"# datapackage-java\n\n[![License](https://img.shields.io/github/license/frictionlessdata/datapackage-java.svg)](https://github.com/frictionlessdata/datapackage-java/blob/master/LICENSE)\n[![Release](https://img.shields.io/jitpack/v/github/frictionlessdata/datapackage-java)](https://jitpack.io/#frictionlessdata/datapackage-java)\n[![Codebase](https://img.shields.io/badge/codebase-github-brightgreen)](https://github.com/frictionlessdata/datapackage-java)\n[![Support](https://img.shields.io/badge/support-discord-brightgreen)](https://discordapp.com/invite/Sewv6av)\n\nA Java library for working with Data Packages according to the \n[Frictionless Data](https://specs.frictionlessdata.io/data-package/) specifications. \nA Data Package is a simple container format for creating self-contained packages of data. It provides the basis \nfor convenient delivery, installation and management of datasets. It shares some similarity with simple database \nformats, but lacks a robust query engine, instead focusing on exchanging bundles of related data.\n\nPlease find releases on [Jitpack](https://jitpack.io/#frictionlessdata/datapackage-java)\n\n## Usage\n\n- [Create a Data Package](#create_a_data_package) explains how to create a Data Package\n- [Iterate through Data](#iterate_through_data) explains how to iterate through data in Resources\n- [Edit a Data Package](#edit_a_data_package) explains how to add or remove Resources or properties to or from a Data Package\n- [Save to File](#save_to_file) explains how to save a Data Package to a file\n- [Working with Foreign Keys](docs/foreign-keys.md) explains how to set foreign key constraints in Data Packages\n- [Contributing](#contributing) contributions are welcome\n\n### Create a Data Package\n\n#### From JSONObject Object\n\n```java\n// Create JSON Object for testing\nJSONObject jsonObject = new JSONObject(\"{\\\"name\\\": \\\"test\\\"}\");\n\n// Build resources.\nJSONObject resource1 = new JSONObject(\"{\\\"name\\\": \\\"first-resource\\\", \\\"path\\\": [\\\"foo.txt\\\", \\\"bar.txt\\\", \\\"baz.txt\\\"]}\");\nJSONObject resource2 = new JSONObject(\"{\\\"name\\\": \\\"second-resource\\\", \\\"path\\\": [\\\"bar.txt\\\", \\\"baz.txt\\\"]}\");\n\nList resourceArrayList = new ArrayList();\nresourceArrayList.add(resource1);\nresourceArrayList.add(resource2);\n\nJSONArray resources = new JSONArray(resourceArrayList);\n\n// Add the resources.\njsonObject.put(\"resources\", resources);\n\n// Build the datapackage.\nPackage dp = new Package(jsonObject, true); // Set strict validation to true.\n```\n\n#### From JSON String\n\n```java\n// The path of the datapackage file.\nString filepath = \"/path/to/file/datapackage.json\";\n\n// Get string content version of source file.\nString jsonString = new String(Files.readAllBytes(Paths.get(filepath)));\n\n// Create DataPackage instance from jsonString.\nPackage dp = new Package(jsonString, true); // Set strict validation to true.\n```\n\n#### From Remote File\n\n```java\nURL url = new URL(\"https://raw.githubusercontent.com/frictionlessdata/datapackage-java/master/src/test/resources/fixtures/multi_data_datapackage.json\");\nPackage dp = new Package(url, true); // Set strict validation to true.\n```\n\n#### From Local JSON File\n\n```java\nString relativePath = \"datapackage.json\";\nString basePath = \"/data\";\n        \n// Build DataPackage instance based on source file path.\nPackage dp = new Package(relativePath, basePath, true); // Set strict validation to true.\n```\n\n#### From Local Zip File\n```java\nPackage dp = new Package(\"/path/of/zip/file/datapackage.zip\", true); // Set strict validation to true.\n```\n\nExceptions are thrown for the following scenarios:\n- The zip archive must contain a file named _datapackage.json_. If no such file exists, a `DataPackageException` will be thrown.\n- If _datapackage.json_ does exist but it is invalid and validation is enabled then a `ValidationException` will be thrown.\n- If the zip file does not exist, an `IOException` will be thrown.\n\n\n### Iterate through Data\n#### Without Casting\n```java\n// Get the resource from the data package.\nResource resource = pkg.getResource(\"first-resource\");\n\n// Set the profile to tabular data resource (if it hasn't been set already).\nresource.setProfile(Profile.PROFILE_TABULAR_DATA_RESOURCE);\n\n// Get Iterator.\nIterator\u003cString[]\u003e iter = resource.iter();\n\n// Iterate.\nwhile(iter.hasNext()){\n    String[] row = iter.next();\n    String city = row[0];\n    String population = row[1];\n} \n```\n\n#### With Casting\n\n```\n// Get Iterator. \n// Third boolean is the cast flag (First on is for keyed and second for extended).\nIterator\u003cObject[]\u003e iter = resource.iter(false, false, true));\n\n// Iterator\nwhile(iter.hasNext()){\n    Object[] row = iter.next();\n    String city = row[0];\n    Integer population = row[1];\n} \n```\n\n### Edit a Data Package\n\n#### Add a Resource\n\n```java\n// Create a data package.\nPackage dp = new Package();\n\n// Add a resource.\nResource resource = new Resource(\"new-resource\", \"data.csv\");\ndp.addResource(resource);\n```\n\nA `DataPackageException` will be thrown if the name of the new resource that is being added already exists.\n\n#### Remove a Resource\n\n```java\n// Create a data package.\nURL url = new URL(\"https://raw.githubusercontent.com/frictionlessdata/datapackage-java/master/src/test/resources/fixtures/multi_data_datapackage.json\");\nPackage dp = new Package(url);\n\n// Remove a resource.\ndp.removeResource(\"third-resource\");\n```\n\n#### Add a Property\n\n```java\n// Create a data package\nPackage dp = new Package();\n\n// Add a few properties.\ndp.addProperty(\"name\", \"a-unique-human-readable-and-url-usable-identifier\");\ndp.addProperty(\"title\", \"A nice title\");\ndp.addProperty(\"id\", \"b03ec84-77fd-4270-813b-0c698943f7ce\");\ndp.addProperty(\"profile\", \"tabular-data-package\");\n\n// Create and add license array.\nJSONObject license = new JSONObject();\nlicense.put(\"name\", \"ODC-PDDL-1.0\");\nlicense.put(\"path\", \"http://opendatacommons.org/licenses/pddl/\");\nlicense.put(\"title\", \"Open Data Commons Public Domain Dedication and License v1.0\");\n\nJSONArray licenses = new JSONArray();\nlicenses.put(license);\n\ndp.addProperty(licenses);\n```\n\nA `DataPackageException` will be thrown if the key of the new property that is being added already exists.\n\n\n#### Remove a Property\n\n```java\n// Create a data package\nPackage dp = new Package();\n\n// Add a few properties.\ndp.addProperty(\"name\", \"a-unique-human-readable-and-url-usable-identifier\");\ndp.addProperty(\"title\", \"A nice title\");\n\n// Remove the title property.\ndp.removeProperty(\"title\");\n```\n\n### Save to File\n\n#### JSON File\n```java\nURL url = new URL(\"https://raw.githubusercontent.com/frictionlessdata/datapackage-java/master/src/test/resources/fixtures/multi_data_datapackage.json\");\nPackage dp = new Package(url);\n\ndp.save(\"/destination/path/datapackage.json\")\n```\n\n\n#### Zip File\n```java\nURL url = new URL(\"https://raw.githubusercontent.com/frictionlessdata/datapackage-java/master/src/test/resources/fixtures/multi_data_datapackage.json\");\nPackage dp = new Package(url);\n\ndp.save(\"/destination/path/datapackage.zip\")\n```\n\n## Contributing\n\nFound a problem and would like to fix it? Have that great idea and would love to see it in the repository?\n\n\u003e [!NOTE]\n\u003e Please open an issue before you start working.\n\nIt could save a lot of time for everyone and we are super happy to answer questions and help you along the way. Furthermore, feel free to join [frictionlessdata Gitter chat room](https://gitter.im/frictionlessdata/chat) and ask questions.\n\nThis project follows the [Open Knowledge International coding standards](https://github.com/okfn/coding-standards).\n\nGet started:\n```sh\n# install jabba and maven2\n$ cd datapackage-java\n$ jabba install 17\n$ jabba use 17\n$ mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V\n$ mvn test -B\n```\n\nMake sure all tests pass.\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrictionlessdata%2Fdatapackage-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrictionlessdata%2Fdatapackage-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrictionlessdata%2Fdatapackage-java/lists"}