Jump to content

Translating XML to Json


Recommended Posts

I have a workflow based on an AppleScript that I hacked together and it uses xml, I would like to change this to Json but I don't have enough knowledge to do so myself. I am aware that Applescript is not a great language, and that it is not very popular here, but it is the only language that I know a little bit of.

 

If you can help me to "translate" the script below to use Json instead of xmI I would appreciate it.

 

set MyList to {¬
	{Country:"Country 1", Ofset:1}, ¬
	{Country:"Country 2", Ofset:2}}

set MyItems to ""

repeat with j from 1 to (count MyList)
	
	set MyCountry to Country of item j of MyList
	set MyOffset to Ofset of item j of MyList
	
	set DatePlusOffset to (current date) + MyOffset * hours
	set DateFormatted to weekday of DatePlusOffset & " " & (text 1 thru -4 of time string of DatePlusOffset) as text
	
	set MyItems to "<items>¬
		<item uid='" & MyCountry & "' arg='" & MyCountry & "' valid='yes'>¬
		<title>" & MyCountry & " " & DateFormatted & "</title>¬
		<subtitle></subtitle>¬
		<icon>icon.png</icon>¬
		</item>" & return & MyItems
	
end repeat

return "<?xml version='1.0'?>" & MyItems & "</items>"

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...