Topic
  • 6 replies
  • Latest Post - ‏2011-04-22T13:48:55Z by mburati
SystemAdmin
SystemAdmin
1493 Posts

Pinned topic What can I do with a JSON object?

‏2011-04-17T13:40:58Z |
My web service returns a JSON string. For example:
<htmlDocument>{"output":{"outVar":"yada"},"__status":"end"}</htmlDocument>

I want to parse the JSON and iterate through the structure. But the only builder that I see that deals with JSON is the XML to JSON Converter builder.

So my guess is that PF can't help me with JSON- I need to look at Java packages. Is this right?

Thanks,
Eli
Updated on 2011-04-22T13:48:55Z at 2011-04-22T13:48:55Z by mburati
  • mburati
    mburati
    425 Posts

    Re: What can I do with a JSON object?

    ‏2011-04-18T20:07:03Z  
    WPF tends to use XML as the server side runtime data representation so having the JSON transformed to XML and then iterate it that way would be what most WPF developers would do. Since JSON is more typically used in the browser via javascript, there aren't builders that manipulate it (other than converting to/from XML) on the server side.

    ..mb1
  • SystemAdmin
    SystemAdmin
    1493 Posts

    Re: What can I do with a JSON object?

    ‏2011-04-21T12:37:13Z  
    • mburati
    • ‏2011-04-18T20:07:03Z
    WPF tends to use XML as the server side runtime data representation so having the JSON transformed to XML and then iterate it that way would be what most WPF developers would do. Since JSON is more typically used in the browser via javascript, there aren't builders that manipulate it (other than converting to/from XML) on the server side.

    ..mb1
    other than converting to/from XML) on the server side.???

    I see that the XML to JSON builder transforms xml to json. But which builder transforms json to xml?
    Thanks,
    Eli
  • kevintap
    kevintap
    111 Posts

    Re: What can I do with a JSON object?

    ‏2011-04-21T14:24:41Z  
    other than converting to/from XML) on the server side.???

    I see that the XML to JSON builder transforms xml to json. But which builder transforms json to xml?
    Thanks,
    Eli
    The REST Service Call builder will automatically convert JSON to XML and create a schema from the data. You may want to evaluate using the REST Service Call builder instead of the Web Service Call builder to access your back end services.
  • SystemAdmin
    SystemAdmin
    1493 Posts

    Re: What can I do with a JSON object?

    ‏2011-04-21T14:26:27Z  
    other than converting to/from XML) on the server side.???

    I see that the XML to JSON builder transforms xml to json. But which builder transforms json to xml?
    Thanks,
    Eli
    I'm not 100% sure I have a good picture of your complete use case, but you can check out the Java Doc for the JSONUtil class, which can convert both directions. I believe you need WPF 7.0 though.

    com.bowstreet.util.JSONUtil

    Tom
  • SystemAdmin
    SystemAdmin
    1493 Posts

    Re: What can I do with a JSON object?

    ‏2011-04-21T14:57:15Z  
    I'm not 100% sure I have a good picture of your complete use case, but you can check out the Java Doc for the JSONUtil class, which can convert both directions. I believe you need WPF 7.0 though.

    com.bowstreet.util.JSONUtil

    Tom
    Eureka! JSONUtil does the trick! And no damned jars.

    I would still like to learn how classPath/lib works, but this works great.

    I'm also curious how to tell REST to convert json to xml. What it did was to wrap our JSON as-is in <htmlDocument> </htmlDocument>. We can't figure out where this wrapper came from.

    Thanks big-time,
    Eli
  • mburati
    mburati
    425 Posts

    Re: What can I do with a JSON object?

    ‏2011-04-22T13:48:55Z  
    Eureka! JSONUtil does the trick! And no damned jars.

    I would still like to learn how classPath/lib works, but this works great.

    I'm also curious how to tell REST to convert json to xml. What it did was to wrap our JSON as-is in <htmlDocument> </htmlDocument>. We can't figure out where this wrapper came from.

    Thanks big-time,
    Eli
    Eli,

    Since most of the WPF runtime works by passing around XML, it's wrapping that string in an object type that various parts of the runtime would expect to receive.

    The REST Service Call builder has the ability to "Auto Restructure" REST feeds into something more suitable for display oriented builders to work with (eg, many Atom/RSS feeds aren't in an ideal tabular format, so there are restructure handlers that can detect that the feed is Atom / RSS and then wrap repeated entries into a common XML elemnt to contain them to make it easier for page automation to work with them...).

    If you do not select "ignore result" and you select "Auto" as the restructure type and "Generate Schema" (so it knows you want structured XML back), then when the auto feed detection kicks in, it'll ask the JSON handler (after determining that the XMl element isn't Atom/RSS) if it wants to handle that feed. If the XML element (in your case htmlDocument) has no child XML element nodes, then it gets the text element from that node and passes it to JSONUtil.isValid(String) and if that returns true, it'll attempt to use the JSON restructure handler to generate XML from the JSON.

    I hope that info helps,
    ..mb1