Skip to main content

JSON Parse tool JSON-Parse-Tool

One-Tool-Beispiel

Für das JSON-Parse-Tool gibt es ein One-Tool-Beispiel. Unter Beispiel-Workflows erfahren Sie, wie Sie dieses und viele weitere Beispiele direkt in Alteryx Designer aufrufen können.

Verwenden Sie das JSON-Parse-Tool, um JSON-Text (JavaScript Object Notation) zum Zweck der nachfolgenden Verarbeitung in ein Tabellenschema zu trennen. Dieses Schema kann in ein verwendbares JSON-Format zurückkonvertiert werden, indem Sie die Ausgabe dem Tool JSON Build zuführen.

Configure the Tool

  • JSON Field: Select the fields that hold JSON text. The field must contain valid JSON with all the text for a record in a single cell. Refer to this example:

       {
            "firstName": "John",
            "lastName": "Smith",
            "age": 25,
            "address": {
                    "streetAddress": "21 2nd Street",
                    "city": "New York",
                    "state": "NY",
                    "postalCode": "10021"
    },
    "phoneNumber": [
            {
                    "type": "home",
                    "number": "212 555-1234"
            },
            {
                    "type": "fax",
                    "number": "646 555-4567"
            }
        ]
    }
  • Input in Output: The selected column is included in the data stream coming out of the tool.

Choose how the JSON gets parsed. Choices include...

  • Output values into single string field

  • Output values into data type specific fields

  • Unnest JSON field: This option is available via AMP only.

  • Flatten array: This option is available via AMP only.

Refer to the sections below for additional information and examples for each of the above options.

This option outputs 2 fields: JSON_Name and JSON_ValueString. Using the input example above, this data comes out of the tool:

Example

JSON Input
   {
        "firstName": "John",
        "lastName": "Smith",
        "age": 25,
        "address": {
                "streetAddress": "21 2nd Street",
                "city": "New York",
                "state": "NY",
                "postalCode": "10021"
},
"phoneNumber": [
        {
                "type": "home",
                "number": "212 555-1234"
        },
        {
                "type": "fax",
                "number": "646 555-4567"
        }
    ]
}
JSON Parse Tool Output

JSON_Name

JSON_ValueString

firstName

John

lastName

Smith

age

25

address.streetAddress

21 2nd Street

address.city

New York

address.state

NY

address.postalCode

10021

phoneNumber.0.type

home

phoneNumber.0.number

212-555-1234

phoneNumber.1.type

fax

phoneNumber.1.number

646-555-4567

This option outputs these 5 fields:

Feldname

Beschreibung

JSON_Name

„JSON_Name“ ist der „Schlüssel“ eines JSON-Objekts (Schlüssel:Wert-Paar). Der Schlüssel und die hierarchischen Kategorien werden durch einen Punkt voneinander getrennt.

JSON_Value String

Der entsprechende „Wert“ für die Zeichenfolge des JSON-Objekts (Schlüssel:Wert-Paar). Wenn der Wert keine Zeichenfolge ist, wird er als [Null] angezeigt.

JSON_ValueInt

Der entsprechende ganzzahlige „Wert“ des JSON-Objekts (Schlüssel:Wert-Paar). Wenn der Wert keine ganze Zahl ist, wird er als [Null] angezeigt.

JSON_ValueFloat

Der entsprechende „Gleitkommawert“ des JSON-Objekts (Schlüssel:Wert-Paar). Wenn der Wert kein Gleitkommawert ist, wird er als [Null] angezeigt.

JSON_ValueBool

Der entsprechende boolesche „Wert“ des JSON-Objekts (Schlüssel:Wert-Paar). Wenn der Wert kein boolescher Wert ist, wird er als [Null] angezeigt.

Example

JSON Input
   {
        "firstName": "John",
        "lastName": "Smith",
        "age": 25,
        "address": {
                "streetAddress": "21 2nd Street",
                "city": "New York",
                "state": "NY",
                "postalCode": "10021"
},
"phoneNumber": [
        {
                "type": "home",
                "number": "212 555-1234"
        },
        {
                "type": "fax",
                "number": "646 555-4567"
        }
    ]
}
JSON Parse Tool Output

JSON_Name

JSON_ValueString

JSON_ValueInt

JSON_ValueFloat

JSON_ValueBool

firstName

John

[Null]

[Null]

[Null]

lastName

Smith

[Null]

[Null]

[Null]

age

[Null]

25

[Null]

[Null]

address.streetAddress

21 2nd Street

[Null]

[Null]

[Null]

address.city

New York

[Null]

[Null]

[Null]

address.state

NY

[Null]

[Null]

[Null]

address.postalCode

10021

[Null]

[Null]

[Null]

phoneNumber.0.type

home

[Null]

[Null]

[Null]

phoneNumber.0.number

212-555-1234

[Null]

[Null]

[Null]

phoneNumber.1.type

fax

[Null]

[Null]

[Null]

phoneNumber.1.number

646-555-4567

[Null]

[Null]

[Null]

This option allows to un-nest JSON objects into columns. It goes only one level deeper into the JSON object.

Warnung

Unnest JSON Field is available via AMP only.

Example

JSON Input

Consider an "hours" column in the input with these values:

{    
    "Tuesday": {"close": "17:00", "open": "08:00"},
    "Friday": {"close": "17:00", "open": "08:00"},
    "Monday": {"close": "17:00", "open": "08:00"},
    "Wednesday": {"close": "17:00", "open": "08:00"},
    "Thursday": {"close": "17:00", "open": "08:00"}
}
JSON Parse Tool Output

This is the output when you unnest the above "hours" column:

hours.Tuesday

hours.Friday

hours.Monday

hours.Wednesday

hours.Thursday

{"close":"17:00","open":"08:00"}

{"close":"17:00","open":"08:00"}

{"close":"17:00","open":"08:00"}

{"close":"17:00","open":"08:00"}

{"close":"17:00","open":"08:00"}

  • Unnest on the "hours" column outputs columns "hours.Tuesday", "hours.Friday", "hours.Monday" and so on.

  • "hours.Tuesday" continues to carry the object: {"close": "17:00", "open": "08:00"}. You can unnest this again to hours.Tuesday.close and hours.Tuesday.open with another Json Parse tool.

This option is applicable for columns that have array values only. It allows you to expand a JSON array column by removing the square brackets. It creates a separate row for each element separated by a comma and assigns an ID for each row.

Warnung

Flatten Array is available via AMP only.

Example

JSON Input

Consider this array input in square brackets where the column name is "hours" and the column value is an array:

[    
    {"day": "Monday", "open": "08:00", "close": "17:00"},
    {"day": "Tuesday", "open": "08:00", "close": "17:00"},
    {"day": "Wednesday", "open": "08:00", "close": "17:00"},
    {"day": "Thursday", "open": "08:00", "close": "17:00"},
    {"day": "Friday", "open": "08:00", "close": "17:00"}
]
JSON Parse Tool Output

hours_flatten

hours_idx

{"day":"Monday","open":"08:00","close":"17:00"}

1

{"day":"Tuesday","open":"08:00","close":"17:00"}

2

{"day":"Wednesday","open":"08:00","close":"17:00"}

3

{"day":"Thursday","open":"08:00","close":"17:00"}

4

{"day":"Friday","open":"08:00","close":"17:00"}

5