# UPDATED: Hierarchical Textfile to JSON

**URL:** <https://forum.xojo.com/t/updated-hierarchical-textfile-to-json/26396>\
**Category:** Getting Started\
**Created:** [August 31, 2015, 9:34pm UTC](https://forum.xojo.com/t/updated-hierarchical-textfile-to-json/26396 "2015-08-31T21:34:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_T](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/a88e57/32.png) [@Martin\_T](https://forum.xojo.com/u/Martin_T)\
**Post date:** [August 31, 2015, 9:34pm UTC](https://forum.xojo.com/t/updated-hierarchical-textfile-to-json/26396/1 "2015-08-31T21:34:35Z")

</div>

Hi everyone,

i have this Sample-Textfile:

`0 File
1 Player Ronaldo
2 Position 2 B
2 Weight 32
3 LastWeight 31
1 Player Pele`

I read the File via Textinputstream. How can i convert this Sample dynamically to a JSON-Structure?

---

<div class="post-metadata">

**Author:** ![Martin\_T](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/a88e57/32.png) [@Martin\_T](https://forum.xojo.com/u/Martin_T)\
**Post date:** [September 1, 2015, 5:54pm UTC](https://forum.xojo.com/t/updated-hierarchical-textfile-to-json/26396/2 "2015-09-01T17:54:58Z")

</div>

OK, i made a small Project, which will show you the (Tree)Structure of that, what i want.

I read the Textfile and parse every Line.  
[h]Line-Syntax[/h]

```auto
Level + [Reference] + Tag + [Value]
```

Reference/Value are optional!

Any Object has maximum 5 Sublevels. Means Level from 1 to 5.

Look at the Screenshot, i want to parse these Objects (e.g. INDI, an Object is shown by Level 0) to a JSON-Structure. But i don’t know, how to start the Algorithm.

[Parser-Project](https://drive.google.com/file/d/0B5fyG8EO-sKnd2VQRTFKQnJLcjQ/view?usp=sharing) and [Sample-Textfile](https://drive.google.com/file/d/0B5fyG8EO-sKnc05ZLUE5M0FUdms/view?usp=sharing)

![](http://i58.tinypic.com/2z50q3c.jpg)

[h]Sample JSON-Output[/h]

`{
  "INDI": {
    "ID": "I1",
    "Names": [
        {
          "Full": "Erika /Gabler/",
          "GIVN": "Erika",
          "SURN": "Gabler"
        }
      ],
    "BIRT": {
      "DATE": "12 SEP 1945",
      "PLAC": {
          "Name": "Tempelhof, amerikanischer Sektor, Berlin (West), Berlin, Deutschland",
          "FORM": "Stadtbezirk, Stadtteil, Stadt, Bundesland, Staat",
          "_LOC": "P6"
    },
    "ChildrenOfFamily": [
        {
          "ID": "F2"
        }
      ],
    "SpouseOfFamily": [
        {
          "ID": "F1"
        }
      ],
    "Notes": [
        {
          "Note": "Ehefrau von Max Mustermann",
          "CONT": [
              {
                "Note": "- geboren am 12. September 1945 in Berlin-Tempelhof"
              }
            ]
        }
      ],
    "REFN": "1.a",
    "SEX": "F",
    "_UID": "A51E2894DC914C7997A3441C50B709F9544B"
    }
  }
}`  
Would be great, if you can help me 😉

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [September 2, 2015, 6:03am UTC](https://forum.xojo.com/t/updated-hierarchical-textfile-to-json/26396/3 "2015-09-02T06:03:23Z")

</div>

You need to have a look at the Json part of the docs and then start writing your code. Your question is waaayyyy to generic for us to help you. Try something and if your computer explodes or your Json doesn’t come out the way you want then ask again - a specific question.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:55pm UTC](https://forum.xojo.com/t/updated-hierarchical-textfile-to-json/26396/4 "2020-10-29T17:55:37Z")

</div>


