XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
(Deleted User) Subject: JSON problem
Author: (Deleted User)
Date: 05 Oct 2011 08:24 PM
Originally Posted: 05 Oct 2011 08:21 PM
I can read in the attached file with the help of the JSON XML Converter, but I get an error at line2, column15.
It's valid JSON with other coding tools I use.
What do I need to do?

Ian Thomas
--------------
Stylus Studio 2011 XML Enterprise Suite R2 (Build 1756a)


Document2186768.json.txt
JSON file

Postnext
Ivan PedruzziSubject: JSON problem
Author: Ivan Pedruzzi
Date: 05 Oct 2011 11:25 PM


This JSON structure does not have a single root object therefore its XML representation is not well formed

Wrapping the content into a single element root would solve the problem

<root>
...
</root>

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
(Deleted User) Subject: JSON problem
Author: (Deleted User)
Date: 06 Oct 2011 01:48 AM
Ok, thanks. Can you tell me how I would change the source JSON file so that the mod within SS was not needed?

Originally, this file had [ as its first character, ] as its last. That is handled OK within .NET but I had to remove the enclosing square brackets for SS.

Ian Thomas

Postnext
(Deleted User) Subject: JSON problem
Author: (Deleted User)
Date: 06 Oct 2011 01:50 AM
Somehow, my browser is posting multiple replies if I refresh this page - so I need to log off.
Sorry about that!

Ian Thomas

Postnext
Ivan PedruzziSubject: JSON problem
Author: Ivan Pedruzzi
Date: 06 Oct 2011 02:27 AM

You didn't state what you need to do with the file in Stylus Studio.
One simple thing would be to use XQuery

<root>
{
doc("converter:JSON?2186768.json.txt")
}
</root>


Ivan Pedruzzi
Stylus Studio Team

Postnext
(Deleted User) Subject: JSON problem
Author: (Deleted User)
Date: 06 Oct 2011 02:45 AM
OK I will try that, to fix the JSON. Again, thanks for the help.

What I'm trying to do is outside of Stylus Studio - to generate C# classes from the JSON, which I find it easiest to do from XML. Microsoft has a command-line utility XSD.EXE which can generate the XSD from XML, then the .NET code classes from that XSD file.
The abbreviated syntax of JSON is getting me confused.
--------------
Ian Thomas

Postnext
Ivan PedruzziSubject: JSON problem
Author: Ivan Pedruzzi
Date: 08 Oct 2011 10:26 PM
Ian,

Have you looked at the .net built-in JSON serialize/deserialize feature?


http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx

Posttop
(Deleted User) Subject: JSON problem
Author: (Deleted User)
Date: 09 Oct 2011 04:54 AM
>Ian,
>
>Have you looked at the .net
>built-in JSON
>serialize/deserialize feature?
>
>
>http://msdn.microsoft.com/en-u
>s/library/system.runtime.seria
>lization.json.datacontractjson
>serializer.aspx


Ivan

Yes, in the past 1-2 years I have been using the JSON serialize/deserialise w/o the data contract facility, and it is quite forgiving in that the [ ] enclosing some JSON files is permitted. Then, using regex, it is reasonably simple to process and use arrays or dictionaries (in .NET) to handle the slightly more complex parts.

Also useful is JSON.NET, written by James Newton-King. I used his JSON to XML method (a tiny part of his library).

However, once the schema has been established (and assuming it remains constant) I have found that generated classes are very flexible and powerful for the processing and representation I need to perform.

Initially, the generation of .NET code classes is a little circuitous, particularly if the tokens used by the designers/authors of the JSON data structures are uninformative - eg, "a", "b", ... "f" { "a" "b" "d" "f" ... "s"} - ie, "f" is an array that includes elements "f".

For some years, Microsoft has provided a utility (xsd.exe) with versions of the Windows SDK (free to download), and provided that the JSON can be converted to XML that small command-line utility can generate an XSD, and from that file xsd.exe can produce code classes in VB.NET or C#. The latest couple of versions of xsd.exe do a good job with the code generation, and with some manipulation and supplementary code I have been able to make some good progress.

Once that is done, JSON.NET and other tools are not needed.

Stylus Studio doesn't really play a part in this process, for me - except, of course, for your reminder that I had no root element in the imported JSON (and after I had removed the [] from those files).

I haven't looked at the XML Importer tools with SS, but it's possible that the [ ] could be removed and replaced with a root element in the XML (which is essentially what it represents, to my understanding); and that SS could be used to make JSON/XML files like the one I gave as an example a lot more readable (so the "f" {... "f"} complication does not take so long to untangle in generated C# code classes); and I assume SS could call xsd.exe to generate these classes, too.

On reading over the above, I think that this may be a bit confusing w/o seeing the 2 groups of JSON files I have been dealing with.

Ian Thomas
--------------
Stylus Studio 2011 XML Enterprise Suite R2 (Build 1756a)

 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.