NetTalk Central

Author Topic: JSON to XML and vice versa  (Read 5431 times)

Thys

  • Sr. Member
  • ****
  • Posts: 311
    • View Profile
    • Incasu
    • Email
JSON to XML and vice versa
« on: May 04, 2017, 03:36:06 AM »
Hi,

Just wondering if there is an easy way to convert from JSON to XML and vice versa? Should probably be methods within jfiles and xfiles.

Thys

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: JSON to XML and vice versa
« Reply #1 on: May 05, 2017, 01:08:52 AM »
it's an intriguing idea,
are you thinking of a "known" structure, or "any" structure?

cheers
Bruce

osquiabro

  • Hero Member
  • *****
  • Posts: 687
    • View Profile
    • Email
Re: JSON to XML and vice versa
« Reply #2 on: May 05, 2017, 04:41:58 AM »

Thys

  • Sr. Member
  • ****
  • Posts: 311
    • View Profile
    • Incasu
    • Email
Re: JSON to XML and vice versa
« Reply #3 on: May 08, 2017, 12:24:38 AM »
Hi Bruce.

Both jFiles and xFiles work from the premise on the one side to have a fixed Clarion data structure, and on the other side the formatted text structure - and the class methods assist to convert from the one structure to the other. But with this I think it would be (for example) an XML object being created from a JSON object's method - and vice versa, so there should be no need for a Clarion structure to do the conversion.

Thys

Thys

  • Sr. Member
  • ****
  • Posts: 311
    • View Profile
    • Incasu
    • Email
Re: JSON to XML and vice versa
« Reply #4 on: May 08, 2017, 12:25:46 AM »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: JSON to XML and vice versa
« Reply #5 on: May 08, 2017, 07:03:54 AM »
If both had an interim "format free" state then yes, you are right, it should be possible.
jFiles does have such a state, but alas xFiles does not.

So it would be relatively easy to create xml from Json - simply by adding an output method to jFiles so save the interim state to xml instead of json.

In practice everyone would want waaay too much control over the xml - this should be an attribute, that should be a field, and so on.

I'm sure there are tools to do this, but it's not a road I have a need to go down <g>.

cheers
Bruce