XElement, from tree to spread best practice?

Hey all!

I was wondering if there is some guidance/tutorial about best practice to go from xml-string (actually json->xml) to spreads … in other words from tree to spreads.

I’m trying to get to grips with something like this where i would need to access item->fields->id:title->value.

<root type="array">
  <item type="object">
    <fields type="array">
      <item type="object">
        <event_id type="number">78101</event_id>
        <id type="string">created_at</id>
        <value type="string">Wed Sep 12 2012 09:27:13 GMT+0200 (CEST)</value>
      </item>
      <item type="object">
        <event_id type="number">78101</event_id>
        <id type="string">fn_local</id>
        <value type="string">.mp4</value>
      </item>
      <item type="object">
        <event_id type="number">78101</event_id>
        <id type="string">fn_s3</id>
        <value type="string">.mp4</value>
      </item>
      <item type="object">
        <event_id type="number">78101</event_id>
        <id type="string">title</id>
        <value type="string">deborah-explanation</value>
      </item>
      <item type="object">
        <event_id type="number">78101</event_id>
        <id type="string">type</id>
        <value type="string">video</value>
      </item>
      <item type="object">
        <event_id type="number">78101</event_id>
        <id type="string">updated_at</id>
        <value type="string">Thu May 31 2012 09:22:48 GMT+0200 (CEST)</value>
      </item>
      <item type="object">
        <event_id type="number">78101</event_id>
        <id type="string">vid_type</id>
        <value type="string">other</value>
      </item>
    </fields>
    <id type="number">78101</id>
    <event_group_id type="number">29</event_group_id>
    <created_by_user_id type="number">1234</created_by_user_id>
    <utc_timestamp type="number">1298019600.0</utc_timestamp>
    <duration type="number">2782.0</duration>
    <type type="string">video</type>
    <token type="null"></token>
  </item>
</root>

Thanks!

check the XElement category, there should be help patches and probably some girlpower.

Thx! I already did and ended up doing something like this (attached) … just not sure if this is “clean” and how it should be.

xml-parsing.v4p (28.4 kB)

ai fjen, without thinking too much about it, i am assuming this can be done more straight fwd using xpath. please see if
\girlpower\Strings\02_XMLOperations_Overview.v4p
helps…

you might want to check out Prune (XElement) which is intended for flattening a tree to a spread

Can you post the original json?

You might be able to go straight from the json to Message with AsMessage (string) and use Read (Message) to get any specific field you want in one easy spread of your choice.

The upside if this works is, you might then be able to stream your original file with Reader (Message), without huge loading times or even xpath’ing a complete dance performance in one frame.

Oh great! I’ll hug you all at NODE!

@velcrome

I can’t seem to get AsMessage to accept the JSON, returns nil … do you see why?

[{
	"fields": [{
		"event_id": 78101,
		"id": "created_at",
		"value": "Wed Sep 12 2012 09:27:13 GMT+0200 (CEST)"
	}, {
		"event_id": 78101,
		"id": "fn_local",
		"value": ".mp4"
	}, {
		"event_id": 78101,
		"id": "fn_s3",
		"value": ".mp4"
	}, {
		"event_id": 78101,
		"id": "title",
		"value": "deborah-explanation"
	}, {
		"event_id": 78101,
		"id": "type",
		"value": "video"
	}, {
		"event_id": 78101,
		"id": "updated_at",
		"value": "Thu May 31 2012 09:22:48 GMT+0200 (CEST)"
	}, {
		"event_id": 78101,
		"id": "vid_type",
		"value": "other"
	}],
	"id": 78101,
	"event_group_id": 29,
	"created_by_user_id": 1234,
	"utc_timestamp": 1298019600.0,
	"duration": 2782.0,
	"type": "video",
	"token": null
}]

Ah, null is causing trouble …

please replace VVVV.Packs.Messaging.dll in both the /core and the /nodes/plugins directory inside the pack with the correct version and report

quick drop in (41.8 kB)

OK, not sure if i did this right. Fetched NuGet.exe, ran from cmd.exe and installed vvvv.packs.message 2.0.1 … then took that .dll and replaced it inside a fresh copy from here. null-problem gone, thanks!

… and just now realized that you added that .dll as download above. Meeh.