JSON parser

What new features you would like to see in next QM version?

JSON parser

Postby stupomer on Thu Apr 16, 2015 4:46 pm

Hi Gintaras,
Would it be hard to incorporate a JSON parser similar to the IXml and IXmlNode interfaces already in QM?
There is something from MS called System.Runtime.Serialization.Json

Is there a .NET limitation of QM for this?

User avatar
Active Member
Posts: 925
Joined: Fri Mar 23, 2007 2:22 am
Location: Boston, USA

Re: JSON parser

Postby Gintaras on Fri Apr 17, 2015 1:12 pm

Function JsonToXml     ?
function'IXml $JSON [flags] ;;flags: 1 display XML text in QM output

;Converts JSON text to XML and returns IXml object.

;On Windows XP SP2 and Vista must be installed .NET 3.5 or later. Older OS are not supported.

;str JSON=
;;;;;"hello": "world",
;;;;;"t": true ,
;;;;;"f": false,
;;;;;"n": null,
;;;;;"i": 123,
;;;;;"pi": 3.14,
;;;;;"Address": { "City": "New York", "State": "NY" },
;;;;;"a": [1, 2, 3, 4]
;IXml x=JsonToXml(JSON 1)
;IXmlNode r=x.RootElement
;;get simple
;out r.Child("hello").Value
;;get with XPath
;out r.Path("Address/State").Value
;;get array
;ARRAY(IXmlNode) a; r.Path("a/*" a)
;int i; for(i 0 a.len) out a[i].Value

opt noerrorshere 1
CsScript x.SetOptions("references=System.Xml;System.Runtime.Serialization;System.ServiceModel.Web")
_s=x.Call("ToXml" JSON)
if(flags&1) out _s
IXml k._create
ret k

using System;
using System.Text;
using System.Runtime.Serialization.Json;
using System.Xml;
using System.Xml.Linq;

public class Json
static public string ToXml(string JSON)
XmlDictionaryReader reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(JSON), new System.Xml.XmlDictionaryReaderQuotas());
return XElement.Load(reader).ToString();


Site Admin
Posts: 10412
Joined: Thu Dec 19, 2002 7:36 pm
Location: Lithuania

Re: JSON parser

Postby stupomer on Fri Apr 17, 2015 9:38 pm

Wow....is there anything QM (and Gintaras) cant do?
Thanks so much! !

User avatar
Active Member
Posts: 925
Joined: Fri Mar 23, 2007 2:22 am
Location: Boston, USA

Return to Wish List

Who is online

Users browsing this forum: No registered users and 1 guest