Jsonmbs

Are there any ‘getting started’ guides for JSONMBS?
I currently use XML to store a complex object, and from what I read, JSON and JSONMBS in particular, should make reading from such a text structure much faster

Ive never used JSON… looked up online , found ‘Parse’ as a starting point, then I find that JPONMBS doesnt have such a thing and got confused.

Any examples of creating / manipulating a complex JSON structure

Right now, I use an xml doc
with a
Properties section (strings, integers)
Objects of a Type section, holding such objects, each with attributes
Objects of another type, holding such objects, with attributes
etc

eg

size ="22" color ="Red" meal = "Sandwich" fuel="Diesel" color = "red" make = "Ford" fuel="Petrol" color = "blue" make = "GM"

Not sure what you want here.

But if you have a block of JSON to parse, you can pass it to the constructor of JSONMBS class.

If you need to build JSON from scratch, you may need to create new nodes with the New methods there and then add the to array and object JSONMBS objects.

I will need to build nodes from scratch.
I cant (yet) see how that is done for anything other than a single value.
eg I can see how to add a string, or an integer, or even an array
I cannot (yet) find a way to do that , and then later access some of the items in the JSON file.

How would I build a document like the one above with ‘new’ methods?

In the cars example, if I got them ‘in’, how would I change the color of the second car, for example?

Post 1 simple XML that holds one example of what you want to achieve and we can mimic a JSON equivalent.

Not sure if it helps but I think of json as a nested dictionary. Christian has a nice example in the Util->JSON folder called “JSON.xojo_binary_project” that shows quite a bit. In my experience it depends on how you want to use or how the publisher uses it as to its structure.

Why do you assume you need a plugin? What doesn’t JSONItem provide that you need?

This is my short example


<?xml version="1.0" encoding="UTF-8"?>
<chart>
	<properties oxsversion="1.0" height="115" width="90" title="" author="" copyright="" instructions="" />
	<palette>
		<palette_item index="1" number="DMC  0" name="Black" color="000000" printcolor="000000"  symbol="100"  />
		<palette_item index="2" number="DMC   3371" name="Black Brown" color="1F0C00" printcolor="1F0C00"  symbol="1"  />
	<palette_item index="23" number="DMC   5200" name="White Bright (B5200)" color="FFFFFF" printcolor="FFFFFF"  symbol="22"  />
	</palette>

	<fullitemss>
		<stitch x="7" y="50" palindex="1"/>
		<stitch x="7" y="54" palindex="1"/>
		<stitch x="7" y="55" palindex="1"/>
		<stitch x="8" y="43" palindex="2"/>
		<stitch x="8" y="44" palindex="1"/>
		<stitch x="8" y="45" palindex="6"/>
			<stitch x="13" y="61" palindex="1"/>
	</fullitemss>
	<partitemss/>
	<comments/>
</chart>

Why do you assume you need a plugin? What doesn’t JSONItem provide that you need?

This:

That post is outdated, JSONItem has gone through significant improvement since that post.

Fair.
But even though I have a current licence, I use Xojo 2015 for my Windows work.

Oh ok, if you’re stuck in an older IDE plugins or Kem’s module can help.

Object chart:

{
   "properties": {
      "oxsversion": "1.0",
      "height": "115",
      "width": "90",
      "title": "",
      "author": "",
      "copyright": "",
      "instructions": ""
   },
   "palette": [
      {
         "index": "1",
         "number": "DMC  0",
         "name": "Black",
         "color": "000000",
         "printcolor": "000000",
         "symbol": "100"
      },
      {
         "index": "2",
         "number": "DMC   3371",
         "name": "Black Brown",
         "color": "1F0C00",
         "printcolor": "1F0C00",
         "symbol": "1"
      },
      {
         "index": "23",
         "number": "DMC   5200",
         "name": "White Bright (B5200)",
         "color": "FFFFFF",
         "printcolor": "FFFFFF",
         "symbol": "22"
      }
   ],
   "fullitemss": [
      {
         "x": "7",
         "y": "50",
         "palindex": "1"
      },
      {
         "x": "7",
         "y": "54",
         "palindex": "1"
      },
      {
         "x": "7",
         "y": "55",
         "palindex": "1"
      },
      {
         "x": "8",
         "y": "43",
         "palindex": "2"
      },
      {
         "x": "8",
         "y": "44",
         "palindex": "1"
      },
      {
         "x": "8",
         "y": "45",
         "palindex": "6"
      },
      {
         "x": "13",
         "y": "61",
         "palindex": "1"
      }
   ],
   "partitemss": [],
   "comments": []
}

You know, { } is Object, and [ ] one array.

1 Like

Thank you all for the input. I more of less follow the way JSON mirrors the XML
I have yet to work out how to create this from. Some research required yet.

1 Like

Here is some food to start


Var j, props, pal, palItem As JSONItem

j = New JSONItem

j.Load(JSONStringConstant) // { "properties": { "oxsversion": ...

props = j.Value("properties")

props.Value("title") = "New title" // Let's change the title

pal = j.Value("palette")

palItem = pal.ValueAt(1) // array, zero based, so the second one

Var DMCNumber As String = palItem.Value("number") // "DMC   3371"

palItem.Value("newPropertyForThis") = "here is it"

Var s As String = j.ToString // j now has a new title, second item on the palette changed too

s =

{
   "properties": {
      "oxsversion": "1.0",
      "height": "115",
      "width": "90",
      "title": "New title",
      "author": "",
      "copyright": "",
      "instructions": ""
   },
   "palette": [
      {
         "index": "1",
         "number": "DMC  0",
         "name": "Black",
         "color": "000000",
         "printcolor": "000000",
         "symbol": "100"
      },
      {
         "index": "2",
         "number": "DMC   3371",
         "name": "Black Brown",
         "color": "1F0C00",
         "printcolor": "1F0C00",
         "symbol": "1",
         "newPropertyForThis": "here is it"
      },
      {
         "index": "23",
         "number": "DMC   5200",
         "name": "White Bright (B5200)",
         "color": "FFFFFF",
         "printcolor": "FFFFFF",
         "symbol": "22"
      }
   ],
   "fullitemss": [
      {
         "x": "7",
         "y": "50",
         "palindex": "1"
      },
      {
         "x": "7",
         "y": "54",
         "palindex": "1"
      },
      {
         "x": "7",
         "y": "55",
         "palindex": "1"
      },
      {
         "x": "8",
         "y": "43",
         "palindex": "2"
      },
      {
         "x": "8",
         "y": "44",
         "palindex": "1"
      },
      {
         "x": "8",
         "y": "45",
         "palindex": "6"
      },
      {
         "x": "13",
         "y": "61",
         "palindex": "1"
      }
   ],
   "partitemss": [],
   "comments": []
}
1 Like