Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pipeline): support reading pretty printed json #345

Merged
merged 8 commits into from
Feb 20, 2024

Conversation

reubenmiller
Copy link
Owner

@reubenmiller reubenmiller commented Feb 17, 2024

Improve pipeline parsing to also accept pretty printed json objects, and also mixing between json objects and non json objects.

The following pipeline formats are now supported:

  • pretty printed json
  • multiple json objects on the same line, e.g. {"name":"1"}{"name":"2"}
  • mixing json and text input
  • trailing newline is no longer required when reading files
  • lines with double quotes surrounding the string

Example: Mixed input

Given the following file input.txt

{"name": "device01"}{"name": "device02"}
    {"name": "device03"}
    device04
"device05"
{
    "name": "device06"
}

You can pipe the above file to c8y:

cat input.txt | c8y devices create --dry

Which will create 5 devices:

| id           | name          |
|--------------|---------------|
| 6424206      | device01      |
| 4924207      | device02      |
| 7822239      | device03      |
| 3422240      | device04      |
| 5223225      | device05      |
| 5264003      | device06      |

Previously, the previously more strict parsing would of only created 3 devices (as invalid lines would of been ignored)

| id           | name          |
|--------------|---------------|
| 6424206      | device01      |
| 7822239      | device03      |
| 3422240      | device04      |

@reubenmiller reubenmiller changed the title feat(pipe): support reading pretty printed json feat(pipeline): support reading pretty printed json Feb 20, 2024
@reubenmiller reubenmiller merged commit b29e4c0 into v2 Feb 20, 2024
4 checks passed
@reubenmiller reubenmiller deleted the feat-pipeline-parser branch February 20, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant