Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert jCard into first-class JSON?

Tags:

json

vcf-vcard

I need a stable and secure convertion algorithm (any language), that can produce the final output as "first class" JSON objects. Example:

  • jCard format: [["version", {}, "text", "4.0"],["fn", {}, "text", "Forrest Gump"]]

  • First-class JSON format: {"version":"4.0","fn":"Forrest Gump"}.

like image 845
Peter Krauss Avatar asked Dec 01 '25 14:12

Peter Krauss


1 Answers

In python first, I create one function named jcard_to_json that takes a jCard as input and converts it to a "first-class" JSON object. The function iterates over the items in the jCard, and for each item, it adds a key-value pair to the json_obj dictionary, where the key is the first item in the jCard thing and the value is the fourth item

Example:-

def jcard_to_json(jcard):
json_obj = {}
for item in jcard:
    json_obj[item[0]] = item[3]
return json_obj

jcard = [["version", {}, "text", "4.0"], ["fn", {}, "text", "Forrest 
Gump"]]
json_obj = jcard_to_json(jcard)
like image 83
Parthish Avatar answered Dec 03 '25 14:12

Parthish