{"id":33242414,"url":"https://github.com/dipakdotyadav/texttojson","last_synced_at":"2026-05-18T07:31:24.210Z","repository":{"id":323496134,"uuid":"1093487035","full_name":"dipakdotyadav/TextToJSON","owner":"dipakdotyadav","description":"Transform unstructured text into structured JSON using human-readable templates.","archived":false,"fork":false,"pushed_at":"2025-11-10T13:17:00.000Z","size":682,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-10T14:28:59.153Z","etag":null,"topics":["charp","dotnet","hacktoberfest","json","parser","template","text-processing"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dipakdotyadav.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-11-10T12:47:45.000Z","updated_at":"2025-11-10T13:17:03.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/dipakdotyadav/TextToJSON","commit_stats":null,"previous_names":["dipakdotyadav/texttojson"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/dipakdotyadav/TextToJSON","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dipakdotyadav%2FTextToJSON","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dipakdotyadav%2FTextToJSON/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dipakdotyadav%2FTextToJSON/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dipakdotyadav%2FTextToJSON/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dipakdotyadav","download_url":"https://codeload.github.com/dipakdotyadav/TextToJSON/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dipakdotyadav%2FTextToJSON/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284767947,"owners_count":27060132,"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-11-16T02:00:05.974Z","response_time":65,"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":["charp","dotnet","hacktoberfest","json","parser","template","text-processing"],"created_at":"2025-11-16T20:01:27.366Z","updated_at":"2025-11-16T20:02:02.724Z","avatar_url":"https://github.com/dipakdotyadav.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![TextToJSON](Text2Json.png)\r\n\r\n# TextToJSON - Powerful Text to JSON Converter\r\n\r\nA flexible .NET library for converting structured text (like invoices, receipts, logs) into JSON using template-based parsing.\r\n\r\n## Features\r\n\r\n- **Template-based parsing** - Define placeholders with data types and transformations\r\n- **Data type conversion** - Automatic conversion to numbers, dates, times, etc.\r\n- **Array/table detection** - Automatically parse repeating rows into JSON arrays\r\n- **Expression engine** - Support for functions and pipelines\r\n- **Pipe operations** - Transform values using pipes (upper, lower, prefix, suffix, etc.)\r\n- **No external dependencies** - Uses only built-in .NET libraries\r\n\r\n## Installation\r\n\r\nThis is a standalone C# file. Simply include `Program.cs` in your project.\r\n\r\n**Requirements:**\r\n- .NET 6.0 or higher\r\n\r\n## Basic Usage\r\n\r\n```csharp\r\n// Define your template\r\nconst string template = @\"\r\n{RetailerName:wordwithspace}\r\n{InvoiceDateTime:datetime:dd-MM-yyyy H:mm}\r\n{TotalAmount:number}\r\n\";\r\n\r\n// Your input text\r\nconst string input = @\"\r\nABC Retailer\r\n15-09-2025 3:45\r\nTotal Amount 246\r\n\";\r\n\r\n// Parse and convert\r\nvar tmpl = TemplateParser.ParseTemplate(template);\r\nvar root = TextToJsonConverter.Convert(input, tmpl);\r\nConsole.WriteLine(root.ToJsonString(new JsonSerializerOptions { WriteIndented = true }));\r\n```\r\n\r\n## Template Syntax\r\n\r\n### Basic Placeholders\r\n\r\n```\r\n{FieldName:datatype:format}\r\n```\r\n\r\n- **FieldName** - The JSON property name\r\n- **datatype** - Optional: `word`, `wordwithspace`, `number`, `integer`, `datetime`, `date`, `time`\r\n- **format** - Optional: Format string for datetime parsing (e.g., `dd-MM-yyyy H:mm`)\r\n\r\n### Examples\r\n\r\n```\r\n{CustomerName:wordwithspace}          // Text with spaces\r\n{InvoiceNumber:word}                   // Single word\r\n{Amount:number}                        // Decimal number\r\n{Quantity:integer}                     // Integer\r\n{Date:date:dd/MM/yyyy}                // Date with custom format\r\n{DateTime:datetime:dd-MM-yyyy H:mm}   // DateTime with custom format\r\n```\r\n\r\n### Array/Table Parsing\r\n\r\nUse `[]` to indicate array fields. All placeholders with the same array base will be parsed as array items.\r\n\r\n```\r\nItem Rate Qty Total\r\n{Items[].ItemName:word} {Items[].Rate:number} {Items[].Quantity:integer} {Items[].Total:number}\r\n```\r\n\r\n**Input:**\r\n```\r\nItem Rate Qty Total\r\nItem1 34 4 136\r\nItem2 55 2 110\r\n```\r\n\r\n**Output:**\r\n```json\r\n{\r\n  \"Items\": [\r\n    {\r\n      \"ItemName\": \"Item1\",\r\n      \"Rate\": 34,\r\n      \"Quantity\": 4,\r\n      \"Total\": 136\r\n    },\r\n    {\r\n      \"ItemName\": \"Item2\",\r\n      \"Rate\": 55,\r\n      \"Quantity\": 2,\r\n      \"Total\": 110\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\n## Pipe Operations\r\n\r\nTransform values using pipes (`|`). Multiple pipes can be chained.\r\n\r\n### Available Pipes\r\n\r\n| Pipe | Description | Example |\r\n|------|-------------|---------|\r\n| `upper()` | Convert to uppercase | `{Name:word \\| upper()}` |\r\n| `lower()` | Convert to lowercase | `{Name:word \\| lower()}` |\r\n| `trim()` | Trim whitespace | `{Value:word \\| trim()}` |\r\n| `prefix('text')` | Add prefix | `{Address:wordwithspace \\| prefix('Addr: ')}` |\r\n| `suffix('text')` | Add suffix | `{Name:word \\| suffix(' Inc.')}` |\r\n| `replace('old', 'new')` | Replace text | `{Value:word \\| replace('-', '/')}` |\r\n| `default('value')` | Default if empty | `{Optional:word \\| default('N/A')}` |\r\n| `tonumber()` | Convert to number | `{Value:word \\| tonumber()}` |\r\n| `dateformat('fmt')` | Format date | `{Date:date \\| dateformat('yyyy-MM-dd')}` |\r\n\r\n### Pipe Examples\r\n\r\n```\r\n{CustomerName:wordwithspace | upper()}\r\n{Address:wordwithspace | prefix('Address: ')}\r\n{Status:word | default('Pending') | upper()}\r\n{Price:number | suffix(' USD')}\r\n```\r\n\r\n**Chaining pipes:**\r\n```\r\n{Name:wordwithspace | trim() | upper() | prefix('Customer: ')}\r\n```\r\n\r\n## Functions\r\n\r\nFunctions can be used in placeholders to compute values.\r\n\r\n### Available Functions\r\n\r\n| Function | Description | Example |\r\n|----------|-------------|---------|\r\n| `coalesce(a, b, ...)` | Return first non-empty value | `{coalesce(CustomerName, RetailerName)}` |\r\n| `concat(a, b, ...)` | Concatenate values | `{concat(FirstName, \" \", LastName)}` |\r\n| `sum(array)` | Sum array values | `{sum(Items[].Total)}` |\r\n| `count(array)` | Count array items | `{count(Items[])}` |\r\n| `join(array, sep)` | Join array with separator | `{join(Items[].Name, \", \")}` |\r\n| `valueof(path)` | Get value at path | `{valueof(CustomerName)}` |\r\n\r\n### Function Examples\r\n\r\n```\r\n{coalesce(CustomerName, \"Unknown\"):wordwithspace}\r\n{sum(Items[].Total):number}\r\n{count(Items[]):integer}\r\n{coalesce(TotalItem, RetailerName) | upper():wordwithspace}\r\n```\r\n\r\n## Complete Example\r\n\r\n```csharp\r\nconst string template = @\"\r\n{RetailerName:wordwithspace}\r\n{InvoiceDateTime:datetime:dd-MM-yyyy H:mm}\r\n{Address:wordwithspace | prefix('Address: ')}\r\n{BillNumber:wordwithspace}\r\nItem Rate Qty Total\r\n{Items[].ItemName:word} {Items[].Rate:number} {Items[].Quantity:integer} {Items[].Total:number}\r\nTotal Amount {TotalAmount:number}\r\nTotal Item {coalesce(TotalItem, RetailerName) | upper():wordwithspace}\r\n\";\r\n\r\nconst string input = @\"\r\nABC Retailer\r\n15-09-2025 3:45\r\nNY,Pal Road, ZN\r\nBill Num 20084\r\nItem Rate Qty Total\r\nItem1 34 4 136\r\nItem2 55 2 110\r\nTotal Amount 246\r\nTotal Item 2\r\nThank You\r\n\";\r\n\r\nvar tmpl = TemplateParser.ParseTemplate(template);\r\nvar root = TextToJsonConverter.Convert(input, tmpl);\r\n\r\nvar options = new JsonSerializerOptions { WriteIndented = true };\r\nConsole.WriteLine(root.ToJsonString(options));\r\n```\r\n\r\n**Output:**\r\n```json\r\n{\r\n  \"RetailerName\": \"ABC Retailer\",\r\n  \"InvoiceDateTime\": \"2025-09-15T03:45:00.0000000\",\r\n  \"Address\": \"Address: NY,Pal Road, ZN\",\r\n  \"BillNumber\": \"Bill Num 20084\",\r\n  \"Items\": [\r\n    {\r\n      \"ItemName\": \"Item1\",\r\n      \"Rate\": 34,\r\n      \"Quantity\": 4,\r\n      \"Total\": 136\r\n    },\r\n    {\r\n      \"ItemName\": \"Item2\",\r\n      \"Rate\": 55,\r\n      \"Quantity\": 2,\r\n      \"Total\": 110\r\n    }\r\n  ],\r\n  \"TotalAmount\": 246,\r\n  \"TotalItem\": \"2\"\r\n}\r\n```\r\n\r\n## Data Types\r\n\r\n| Type | Description | Example Input |\r\n|------|-------------|---------------|\r\n| `word` | Single word (no spaces) | `Invoice123` |\r\n| `wordwithspace` | Text with spaces | `ABC Retailer` |\r\n| `number` / `decimal` | Decimal number | `123.45` |\r\n| `integer` / `int` | Integer number | `42` |\r\n| `datetime` | Date and time | `15-09-2025 3:45` |\r\n| `date` | Date only | `15-09-2025` |\r\n| `time` | Time only | `3:45 PM` |\r\n\r\n## Advanced Features\r\n\r\n### Nested Objects\r\n\r\nUse dot notation for nested JSON objects:\r\n\r\n```\r\n{Customer.Name:wordwithspace}\r\n{Customer.Address.City:wordwithspace}\r\n```\r\n\r\n**Output:**\r\n```json\r\n{\r\n  \"Customer\": {\r\n    \"Name\": \"John Doe\",\r\n    \"Address\": {\r\n      \"City\": \"New York\"\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n### Custom Date Formats\r\n\r\nSpecify format after the data type:\r\n\r\n```\r\n{Date:date:dd/MM/yyyy}\r\n{DateTime:datetime:yyyy-MM-dd HH:mm:ss}\r\n{Time:time:HH:mm}\r\n```\r\n\r\n### Special Characters in Pipes\r\n\r\nYou can include special characters in pipe arguments:\r\n\r\n```\r\n{Address:wordwithspace | prefix('Address:- ')}\r\n{Phone:word | prefix('+1-')}\r\n{Amount:number | suffix(' USD')}\r\n```\r\n\r\n## Tips \u0026 Best Practices\r\n\r\n1. **Array headers** - The parser will automatically skip header lines that match the template literal text\r\n2. **Type inference** - If you don't specify a type, values will be treated as strings\r\n3. **Whitespace** - The parser is flexible with whitespace in both template and input\r\n4. **Regex capture** - For complex patterns, the parser builds capture regexes automatically\r\n5. **Pipeline order** - Pipes are applied left to right, so order matters\r\n\r\n## License\r\n\r\nThis project is provided as-is for educational and commercial use.\r\n\r\n## Contributing\r\n\r\nFeel free to extend this library with additional pipes, functions, or data types as needed for your use case.\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdipakdotyadav%2Ftexttojson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdipakdotyadav%2Ftexttojson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdipakdotyadav%2Ftexttojson/lists"}