Oneliner to covert jcal to usable json
example.jcal | ||
jcal-unfuck.jq | ||
README.md |
jCal unfucker
This oneliner converts the streaming optimised jCal format known as rfc7265, into a developer frendly json structure.
This code was made in anger.
The actual code
jq '.[2] | map({_type: .[0]} + (.[1] | map({key: .[0], value: .[3]}) | from_entries))'
Example Usage
curl -sH 'Accept: application/calendar+json' https://cloud.kraut.space/remote.php/dav/public-calendars/2EkPGt3PF6WwYsA3\?export\&expand\=1\&start\=$(date -d '' +%s)\&end\=$(date -d 'next month' +%s) \
| jq '.[2]|map({_type:.[0]}+(.[1]|map({key:.[0],value:.[3]})|from_entries))'
Okay, but why tho?
- OBJECTS WHERE NOT SUPPOSED TO BE STORED IN ARRAYS!
- Years of iCalendar, WebDAV and CalDAV, yet NO REAL WEB APIs!
- Wanted to hurt youself even more for some kicks? We had an rfc for that: rfc7529
- "Yes, please store the components of the component in arrays of their array! Please fail silently with an empty array if request parameters where invalid." – Statements dreamed up by the uttlery Derenged
On a more serious note
The jCal format may be great for transport and api stability. But if someone actual uses it without an api interface, you can expect bad code that references a lot of array indexes, resulting in unreadable code and longer debug times.
Example of the jCal format
[
"vcalendar",
[
[
"prodid",
{},
"text",
"-//Sabre//Sabre VObject 4.4.2//EN"
],
[
"calscale",
{},
"text",
"GREGORIAN"
],
[
"version",
{},
"text",
"2.0"
],
[
"x-wr-calname",
{},
"unknown",
"Events im KrautSpace (lbehm)"
],
[
"x-apple-calendar-color",
{},
"unknown",
"#9750A4"
],
[
"refresh-interval",
{},
"duration",
"PT4H"
],
[
"x-published-ttl",
{},
"unknown",
"PT4H"
]
],
[
[
"vevent",
[
[
"created",
{},
"date-time",
"2023-10-17T21:13:30Z"
],
[
"dtstamp",
{},
"date-time",
"2023-10-17T21:15:47Z"
],
[
"last-modified",
{},
"date-time",
"2023-10-17T21:15:47Z"
],
[
"sequence",
{},
"integer",
3
],
[
"uid",
{},
"text",
"0449bf5c-41c1-4868-9597-618a74f68377"
],
[
"dtstart",
{},
"date-time",
"2023-11-04T13:00:00Z"
],
[
"dtend",
{},
"date-time",
"2023-11-04T18:00:00Z"
],
[
"status",
{},
"text",
"CONFIRMED"
],
[
"summary",
{},
"text",
"Mitgliederversammlung"
],
[
"location",
{},
"text",
"Hackspace Jena e.V."
],
[
"color",
{},
"unknown",
"khaki"
],
[
"description",
{},
"text",
"Für weitere Informationen siehe: https://senf.kraut.space/t/einladung-zur-mitgliederversammlung-2023/205"
]
],
[]
]
]
]
Output of this script for the example input
[
{
"_type": "vevent",
"created": "2023-10-17T21:13:30Z",
"dtstamp": "2023-10-17T21:15:47Z",
"last-modified": "2023-10-17T21:15:47Z",
"sequence": 3,
"uid": "0449bf5c-41c1-4868-9597-618a74f68377",
"dtstart": "2023-11-04T13:00:00Z",
"dtend": "2023-11-04T18:00:00Z",
"status": "CONFIRMED",
"summary": "Mitgliederversammlung",
"location": "Hackspace Jena e.V.",
"color": "khaki",
"description": "Für weitere Informationen siehe: https://senf.kraut.space/t/einladung-zur-mitgliederversammlung-2023/205"
}
]