{"id":24201550,"url":"https://github.com/mstgnz/transformer","last_synced_at":"2025-09-22T00:31:41.660Z","repository":{"id":40495331,"uuid":"503225728","full_name":"mstgnz/transformer","owner":"mstgnz","description":"Convert yaml, json and xml files into a single Go key-value object","archived":false,"fork":false,"pushed_at":"2024-12-26T15:14:03.000Z","size":367,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-26T15:23:34.231Z","etag":null,"topics":["converter","go","golang","json","transformer","xml","yaml"],"latest_commit_sha":null,"homepage":"","language":"Go","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/mstgnz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"mstgnz"}},"created_at":"2022-06-14T05:49:43.000Z","updated_at":"2024-12-26T15:04:39.000Z","dependencies_parsed_at":"2024-01-31T11:30:49.784Z","dependency_job_id":"70976945-3be7-470a-a600-44ea686309b2","html_url":"https://github.com/mstgnz/transformer","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mstgnz%2Ftransformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mstgnz%2Ftransformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mstgnz%2Ftransformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mstgnz%2Ftransformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mstgnz","download_url":"https://codeload.github.com/mstgnz/transformer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233808733,"owners_count":18733601,"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":["converter","go","golang","json","transformer","xml","yaml"],"created_at":"2025-01-13T21:16:20.189Z","updated_at":"2025-09-22T00:31:36.334Z","avatar_url":"https://github.com/mstgnz.png","language":"Go","funding_links":["https://github.com/sponsors/mstgnz"],"categories":[],"sub_categories":[],"readme":"# Transformer\n\nTransformer is a Go library that enables conversion between different data formats (JSON, XML, YAML). Using a common data structure, you can perform lossless conversions between these formats.\n\n[Turkish Documentation (Türkçe Dokümantasyon)](README_TR.md)\n\n## Features\n\n- Convert between JSON, XML, and YAML formats\n- Consistent conversion with common data structure\n- Easy to use\n- Type safety\n- Customizable conversion rules\n- High test coverage\n- Thread-safe operations\n- Minimal dependencies\n\n## Requirements\n\n- Go 1.16 or higher\n- Dependencies:\n  - `gopkg.in/yaml.v3` for YAML operations\n\n## Installation\n\n```bash\ngo get github.com/mstgnz/transformer\n```\n\n## Usage\n\n### JSON Conversions\n\n```go\nimport \"github.com/mstgnz/transformer/tjson\"\n\n// Read JSON file\ndata, err := tjson.ReadJson(\"data.json\")\nif err != nil {\n    log.Fatal(err)\n}\n\n// Validate JSON format\nif !tjson.IsJson(data) {\n    log.Fatal(\"Invalid JSON format\")\n}\n\n// Convert JSON to Node structure\nnode, err := tjson.DecodeJson(data)\nif err != nil {\n    log.Fatal(err)\n}\n\n// Convert Node structure to JSON\njsonData, err := tjson.NodeToJson(node)\nif err != nil {\n    log.Fatal(err)\n}\n```\n\n### XML Conversions\n\n```go\nimport \"github.com/mstgnz/transformer/txml\"\n\n// Read XML file\ndata, err := txml.ReadXml(\"data.xml\")\nif err != nil {\n    log.Fatal(err)\n}\n\n// Validate XML format\nif !txml.IsXml(data) {\n    log.Fatal(\"Invalid XML format\")\n}\n\n// Convert XML to Node structure\nnode, err := txml.DecodeXml(data)\nif err != nil {\n    log.Fatal(err)\n}\n\n// Convert Node structure to XML\nxmlData, err := txml.NodeToXml(node)\nif err != nil {\n    log.Fatal(err)\n}\n```\n\n### YAML Conversions\n\n```go\nimport \"github.com/mstgnz/transformer/tyaml\"\n\n// Read YAML file\ndata, err := tyaml.ReadYaml(\"data.yaml\")\nif err != nil {\n    log.Fatal(err)\n}\n\n// Validate YAML format\nif !tyaml.IsYaml(data) {\n    log.Fatal(\"Invalid YAML format\")\n}\n\n// Convert YAML to Node structure\nnode, err := tyaml.DecodeYaml(data)\nif err != nil {\n    log.Fatal(err)\n}\n\n// Convert Node structure to YAML\nyamlData, err := tyaml.NodeToYaml(node)\nif err != nil {\n    log.Fatal(err)\n}\n```\n\n### Cross-Format Conversions\n\n```go\n// JSON -\u003e XML conversion\njsonData := []byte(`{\"name\": \"John\", \"age\": 30}`)\nnode, _ := tjson.DecodeJson(jsonData)\nxmlData, _ := txml.NodeToXml(node)\n\n// XML -\u003e YAML conversion\nxmlData := []byte(`\u003croot\u003e\u003cname\u003eJohn\u003c/name\u003e\u003cage\u003e30\u003c/age\u003e\u003c/root\u003e`)\nnode, _ := txml.DecodeXml(xmlData)\nyamlData, _ := tyaml.NodeToYaml(node)\n\n// YAML -\u003e JSON conversion\nyamlData := []byte(\"name: John\\nage: 30\")\nnode, _ := tyaml.DecodeYaml(yamlData)\njsonData, _ := tjson.NodeToJson(node)\n```\n\n## Package Structure\n\n- `node`: Contains core data structure and operations\n  - Node structure for representing hierarchical data\n  - Value types and type conversion operations\n  - Tree traversal and manipulation functions\n- `tjson`: Handles JSON conversion operations\n  - JSON encoding/decoding\n  - JSON validation\n  - JSON file operations\n- `txml`: Handles XML conversion operations\n  - XML encoding/decoding\n  - XML validation\n  - XML file operations\n  - XML attribute handling\n- `tyaml`: Handles YAML conversion operations\n  - YAML encoding/decoding\n  - YAML validation\n  - YAML file operations\n- `example`: Contains example usages\n  - Basic conversion examples\n  - Complex data structure examples\n  - Error handling examples\n\n## Data Types\n\nThe Node structure supports the following data types:\n\n- `TypeNull`: Null value\n- `TypeObject`: Object (key-value pairs)\n  - Supports nested objects\n  - Maintains key order\n  - Handles circular references\n- `TypeArray`: Array\n  - Supports mixed types\n  - Preserves order\n- `TypeString`: String\n- `TypeNumber`: Number (integers and floating-point)\n- `TypeBoolean`: Boolean\n\n## Error Handling\n\nThe library provides detailed error information for various scenarios:\n\n- File operations errors\n- Format validation errors\n- Conversion errors\n- Type mismatch errors\n- Structure validation errors\n\nExample error handling:\n\n```go\nif err := validateAndConvert(); err != nil {\n    switch e := err.(type) {\n    case *FormatError:\n        log.Printf(\"Invalid format: %v\", e)\n    case *ConversionError:\n        log.Printf(\"Conversion failed: %v\", e)\n    default:\n        log.Printf(\"Unexpected error: %v\", e)\n    }\n}\n```\n\n## Testing\n\nThe library has comprehensive test coverage. You can use the following make commands to run tests:\n\n### General Test Commands\n```bash\n# Run all tests\nmake test\n\n# Run all tests with verbose output\nmake test-verbose\n\n# Run tests with coverage\nmake test-cover\n\n# Generate HTML coverage report\nmake test-coverage-report\n```\n\n### Package Specific Tests\n```bash\n# Run JSON tests\nmake test-json\n\n# Run XML tests\nmake test-xml\n\n# Run YAML tests\nmake test-yaml\n\n# Run Node tests\nmake test-node\n\n# Run Benchmark tests\nmake test-bench\n```\n\n### Package Specific Coverage Reports\n```bash\n# Run JSON tests with coverage\nmake test-json-cover\n\n# Run XML tests with coverage\nmake test-xml-cover\n\n# Run YAML tests with coverage\nmake test-yaml-cover\n\n# Run Node tests with coverage\nmake test-node-cover\n```\n\nCurrent test coverage: \u003e90%\n\n## Performance\n\nThe library is optimized for:\n- Memory efficiency\n- CPU usage\n- Large file handling\n- Concurrent operations\n\n### Benchmark Results\n\n```bash\ngoos: darwin\ngoarch: arm64\ncpu: Apple M1\nBenchmarkJSONMarshal-8           4416622               261.0 ns/op           192 B/op          2 allocs/op\nBenchmarkXMLMarshal-8             975189              1230 ns/op            4704 B/op         10 allocs/op\nBenchmarkYAMLMarshal-8            213493              5284 ns/op           16728 B/op         47 allocs/op\nBenchmarkJSONUnmarshal-8         1000000              1742 ns/op             272 B/op          9 allocs/op\nBenchmarkXMLUnmarshal-8           370683              3104 ns/op            2328 B/op         56 allocs/op\nBenchmarkYAMLUnmarshal-8          142972              8640 ns/op           10128 B/op        108 allocs/op\nBenchmarkLargeJSONMarshal-8        66734             17580 ns/op           10953 B/op          2 allocs/op\nBenchmarkLargeXMLMarshal-8         12298             97192 ns/op           33456 B/op         15 allocs/op\nBenchmarkLargeYAMLMarshal-8         2500            466568 ns/op         1581555 B/op       3149 allocs/op\n```\n\n#### Analysis\n- **JSON** shows the best performance in both marshaling and unmarshaling operations\n  - Marshal: ~261 ns/op with only 2 allocations\n  - Unmarshal: ~1.7 µs/op with 9 allocations\n- **XML** performs slower than JSON\n  - Marshal: ~1.2 µs/op with 10 allocations\n  - Unmarshal: ~3.1 µs/op with 56 allocations\n- **YAML** shows the highest resource usage\n  - Marshal: ~5.2 µs/op with 47 allocations\n  - Unmarshal: ~8.6 µs/op with 108 allocations\n- For large data operations:\n  - JSON maintains efficiency with minimal allocations\n  - XML shows moderate performance degradation\n  - YAML shows significant increase in both time and memory usage\n\n## Security\n\n- Input validation to prevent XML entity attacks\n- Memory limit checks for large files\n- Safe type conversions\n- No external command execution\n\n## Contributing\n\nThis project is open-source, and contributions are welcome. Feel free to contribute or provide feedback of any kind.\n\n\n## License\n\nThis project is licensed under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmstgnz%2Ftransformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmstgnz%2Ftransformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmstgnz%2Ftransformer/lists"}