{"id":21923739,"url":"https://github.com/mariazevedo88/json-formatter-validator","last_synced_at":"2025-07-29T16:38:42.486Z","repository":{"id":34294839,"uuid":"170046644","full_name":"mariazevedo88/json-formatter-validator","owner":"mariazevedo88","description":"Java tool for JSON validation via string or file and correction of invalid JSON-like string","archived":false,"fork":false,"pushed_at":"2023-11-13T03:01:02.000Z","size":192,"stargazers_count":10,"open_issues_count":3,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-04T18:11:21.778Z","etag":null,"topics":["coveralls","gson","jacoco","java","java-8","java8","json","json-formatter","json-formatters","json-validation","junit5","string-manipulation"],"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/mariazevedo88.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}},"created_at":"2019-02-11T01:04:55.000Z","updated_at":"2023-12-07T12:28:34.000Z","dependencies_parsed_at":"2023-11-13T04:22:20.866Z","dependency_job_id":null,"html_url":"https://github.com/mariazevedo88/json-formatter-validator","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/mariazevedo88/json-formatter-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariazevedo88%2Fjson-formatter-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariazevedo88%2Fjson-formatter-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariazevedo88%2Fjson-formatter-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariazevedo88%2Fjson-formatter-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mariazevedo88","download_url":"https://codeload.github.com/mariazevedo88/json-formatter-validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mariazevedo88%2Fjson-formatter-validator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267718477,"owners_count":24133457,"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-07-29T02:00:12.549Z","response_time":2574,"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":["coveralls","gson","jacoco","java","java-8","java8","json","json-formatter","json-formatters","json-validation","junit5","string-manipulation"],"created_at":"2024-11-28T21:12:40.313Z","updated_at":"2025-07-29T16:38:42.434Z","avatar_url":"https://github.com/mariazevedo88.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-formatter-validator \n[![Build Status](https://travis-ci.org/mariazevedo88/json-formatter-validator.svg?branch=master)](https://travis-ci.org/mariazevedo88/json-formatter-validator) [![Coveralls github](https://img.shields.io/coveralls/github/mariazevedo88/json-formatter-validator.svg)](https://coveralls.io/github/mariazevedo88/json-formatter-validator?branch=master) ![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/mariazevedo88/json-formatter-validator.svg) ![Sonatype Nexus (Releases)](https://img.shields.io/nexus/r/https/oss.sonatype.org/io.github.mariazevedo88/json-formatter-validator.svg) ![GitHub repo size](https://img.shields.io/github/repo-size/mariazevedo88/json-formatter-validator.svg) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/mariazevedo88/json-formatter-validator.svg) ![GitHub language count](https://img.shields.io/github/languages/count/mariazevedo88/json-formatter-validator.svg) ![GitHub top language](https://img.shields.io/github/languages/top/mariazevedo88/json-formatter-validator.svg) ![GitHub](https://img.shields.io/github/license/mariazevedo88/json-formatter-validator.svg) ![GitHub All Releases](https://img.shields.io/github/downloads/mariazevedo88/json-formatter-validator/total.svg) ![GitHub last commit](https://img.shields.io/github/last-commit/mariazevedo88/json-formatter-validator.svg)\n\n## About json-formatter-validator\n\nLibrary used to format an invalid JSON: a string in a JSON-like format, but no quotation marks on keys and values, or with other errors. The tool works with two input types: string and JSON file. \n\nThe method `checkValidityAndFormatObject()` checks if JSON is valid or not. If JSON is invalid, the string is formatted via regex to add the quotation marks. If JSON is already valid, nothing is done and JSON itself is returned. This functionality can be called as follows:\n\n**Input**\n\n```\nString invalidJSON = \"{id:267107086801,productCode:02-671070868,lastUpdate:2018-07-15,lastUpdateTimestamp:2018-07-15 01:49:58,payment:[{sequential:1,id:CREDIT_CARD,value:188,installments:9}]}\";\nCustomJSONFormatter formatter = new CustomJSONFormatter();\nformatter.checkValidityAndFormatObject(invalidJSON);  \n```\n\n**Output**\n\n```\n19/02/14 00:08:57 INFO jsonformattervalidator.JsonFormatterValidatorApplication: Started Json Formatter Validator Aplication\n19/02/14 00:08:57 INFO formatter.CustomJSONFormatter: Invalid json: {id: 267107086801,productCode:02-671070868,lastUpdate:2018-07-15,lastUpdateTimestamp:2018-07-15 01:49:58,payment:[{sequential:1,id: CREDIT_CARD,value: 188,installments:9}]}\n19/02/14 00:08:57 INFO formatter.CustomJSONFormatter: Valid json: {\"id\":\"267107086801\",\"productCode\":\"02-671070868\",\"lastUpdate\":\"2018-07-15\",\"lastUpdateTimestamp\":\"2018-07-15 01:49:58\",\"payment\":[{\"sequential\":\"1\",\"id\":\"CREDIT_CARD\",\"value\":\"188\",\"installments\":\"9\"}]}\n```\n\nIn versions 2.0 onwards (v.2.0.0, v.2.0.1, etc ...), it is possible to filter one or more attributes of the string that looks like a json or remove one or more attributes, either to discard them by not use or because they are completely corrupted.\n\nExample of the filter option:\n\n**Input**\n\n```\nString invalidJson = \"{id:265998308001,productCode:02-659983080,purchaseDate:2018-01-17,person:{name:Mariana,document:0123456789},deliveryAddress:{street:Rua Fechada,number:666,additionalInfo:casa,city:Lavras,state:MG,zipcode:00000000}}\";\n\nString[] filterById = {\"id\"}; \nString jsonFiltered = formatter.filterJSONObjectsFromString(invalidJson, filterById); \n```\n\n**Output**\n\n```\n\"{id:265998308001,}\"\n```\n\nExample of the remove option:\n\n**Input**\n\n```\nString invalidJson = \"{id:265998308001,productCode:02-659983080,purchaseDate:2018-01-17,person:{name:Mariana,document:0123456789},deliveryAddress:{street:Rua Fechada,number:666,additionalInfo:casa,city:Lavras,state:MG,zipcode:00000000}}\";\n\nString[] fieldsToRemove = {\"person\",\"deliveryAddress\"}; \nString jsonFiltered = formatter.removeJSONObjectsFromString(invalidJson, fieldsToRemove); \n```\n\n**Output**\n\n```\n\"{id:265998308001,productCode:02-659983080,purchaseDate:2018-01-17,}\"\n```\n\nYou can also mute the application logs and thrown exceptions. Just use as a parameter `true` and `true` values for the `muteLog` and the `muteException` variables, respectively, in the method `checkValidityAndFormatObject`, as the example below:\n\n```\nJsonObject invalidJson = formatter.checkValidityAndFormatObject(jsonFormatted, true, true);\n```\n\nTo access the valid JSON, the `getValidJson()` method should be used. Example:\n\n**Input**\n\n```\nJsonObject validJson = formatter.getValidJson();\nJsonElement id = validJson.get(\"id\");\nlogger.info(id.getAsLong());\n```\n\n**Output**\n\n```\n19/02/14 00:08:57 INFO jsonformattervalidator.JsonFormatterValidatorApplication: 267107086801\n```\n\n## Dependencies\n\n- [Java 8](https://www.oracle.com/technetwork/pt/java/javase/downloads/index.html)\n- [Maven](https://maven.apache.org/)\n- [Gson 2.8.9](https://mvnrepository.com/artifact/com.google.code.gson/gson)\n- [log4j 2.16.0](https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core)\n- [JUnit 5](https://junit.org/junit5/docs/current/user-guide/)\n\n## How to use\n\nYou must import .jar into the classpath of your project. If your project is a maven project, just set it as dependency in `pom.xml`, as follows:\n\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.github.mariazevedo88\u003c/groupId\u003e\n  \u003cartifactId\u003ejson-formatter-validator\u003c/artifactId\u003e\n  \u003cversion\u003e2.0.6\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Contributing\n\n[![](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/images/0)](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/links/0)[![](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/images/1)](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/links/1)[![](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/images/2)](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/links/2)[![](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/images/3)](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/links/3)[![](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/images/4)](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/links/4)[![](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/images/5)](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/links/5)[![](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/images/6)](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/links/6)[![](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/images/7)](https://sourcerer.io/fame/mariazevedo88/mariazevedo88/json-formatter-validator/links/7)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariazevedo88%2Fjson-formatter-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmariazevedo88%2Fjson-formatter-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariazevedo88%2Fjson-formatter-validator/lists"}