mangstadt / ez-vcard

A vCard parser library for Java
Other
401 stars 92 forks source link

How to convert standard vCard into first-class JSON? #77

Open ppKrauss opened 7 years ago

ppKrauss commented 7 years ago

There are an ez-vcard option or parameter for it?

I need a stable and secure convertion, that produce the final output as "first class" JSON objects. Example:

mangstadt commented 7 years ago

Sorry, ez-vcard does not produce the kind of JSON output you are looking for.

ppKrauss commented 7 years ago

Hi @mangstadt , thanks! Well, can I help to draft and perhaps develop something for ez-vcard?

I understand that the reversibility ("round-tripping" as RFC 7095) is a key feature of jCard, and it is only possible with expresstions as ["lang", { "pref": "1" }, "language-tag", "fr"], mapping spetial properties, parameters or values. So, jCard can be used as intermediary format (the input) for any other non-reversible format. It is like to write a "vCard report".

The usual goal of non-reversible formats are to express in simplifyed (but also "standard") way the vCard information, for simpler applications... Perhaps the main demand is the construction of Semantic Web expressions, where SchemaOrg is today a de facto standard. See Person, Organization and ContactPoint.


The key files seems JCardRawWriter.java and perhaps JsonValue.java... What do you suggest as a starting point?

ppKrauss commented 7 years ago

Before to move on, in this line of "simple and first-class JSON" (my preference), perhaps you want to check other complex reversible format, the JSON-LD as #78. If we confortable with "simple first", let me explain better.

Maping vCard to SchemaOrg, with equivalences at xCard:

vCard Class Property xCard
FN Person name fn/text
N[1] Person familyName surname
N[2] Person givenName given
N[3] Person additionalName additional
N[4] Person honorificPrefix prefix
N[5] Person honorificSuffix suffix
ORG Organization name org/text
EMAIL Person email email/text
TEL Person telephone tel/uri
BDAY Person birthDate ...
LABEL;HOME Person address adr/parameters/label
LABEL;WORK Organization address ...
ADR[1] PostalAddress postOfficeBoxNumber adr/pobox
ADR[2] PostalAddress ... adr/ext
ADR[3] PostalAddress streetAddress adr/street
... ... ... ...

So there are two natural alternatives to reuse labels: from xCard or from SchemaOrg... But only SchemaOrg is a de facto standard, and express semantic hierarchy, so I prefer SchemaOrg.

Example (from this Wikipedia example):

...
"Person":{
   "name":"Forrest Gump",
   "familyName":"Forrest",
   "givenName":"Gump",
   "honorificPrefix":"Mr.",
   "address":"42 Plantation St.\nBaytown, LA 30314\nUnited States of America",
   "PostalAddress":{
      "streetAddress":"42 Plantation St.",
      "city":"Baytown",
      "postalCode":"30314",
      "addressCountry":"United States of America"
    },
   "telephone":"+1-404-555-1212"
},
"Organization":{
   "name":"Bubba Gump Shrimp Co.",
   "telephone":"+1-111-555-1212",
   "address":"100 Waters Edge\nBaytown, LA 30314\nUnited States of America",
   "PostalAddress":{}
},
...
mangstadt commented 7 years ago

I would treat it as an entirely new data format, and start by creating a new "writer" class.

You could use one of the existing writer classes as a starting point. Because it's based on JSON, you could use the JCardWriter class.

NightMachinery commented 2 years ago

@ppKrauss I have written a JSON outputter using ez-vcard, which might satisfy your needs.