Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

JSON 문자열 해석

항목값
화면 이름Parse JSON string
식별자parseJsonAsSchemaV3
지원 실행 방식Batch, Faster, Streaming
범주데이터 정리 (Data preparation), 자주 쓰는 표현식 (Popular), 문자열 (String), 구조체 (Struct)
반환 자료형Array<AnyType> | Map<String, String> | Struct

지정한 스키마로 JSON 문자열을 해석하며 스키마에 없는 필드는 무시합니다.

입력 인자

이름지정 여부자료형의미와 조건
JSON필수Expression<String>스키마에 따라 해석할 JSON입니다.
Schema필수Type<Array<AnyType> | Map<String, String> | Struct>JSON 문자열을 해석할 스키마 정의입니다.
Output mode선택Enum<Simple, With errors>simple 모드는 해석하지 못한 필드를 null로 처리합니다. with errors 모드는 해석한 JSON을 ok, 파싱 오류를 error 필드에 담은 구조체를 반환합니다.

입출력 예시

예시 1: 기본 동작

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, miles:Integer>>
  • Output mode: null
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": "JFK",
  "miles": 2000
 }
}
{
 airline: XB-112,
 airport: {
 id: JFK,
 miles: 2000,
},
}

예시 2: 기본 동작

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, miles:Integer>>
  • Output mode: WITH_ERRORS
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": "JFK",
  "miles": 2000
 }
}
{
 error: null,
 ok: {
 airline: XB-112,
 airport: {
 id: JFK,
 miles: 2000,
},
},
}

예시 3: 기본 동작

from_json은 바이너리 필드를 Base64 디코딩합니다.

인자 값:

  • JSON: json
  • Schema: Struct<bin:Binary>
  • Output mode: null
json출력
{"bin": "TG9uZG9u"}{
 bin: TG9uZG9u,
}
{"bin": "MQ=="}{
 bin: MQ==,
}
{"bin": "MTI="}{
 bin: MTI=,
}

예시 4: null 처리

입력 JSON에 요청한 필드가 없으면 해당 필드는 null입니다.

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, miles:Integer>>
  • Output mode: null
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": "JFK"
 }
}
{
 airline: XB-112,
 airport: {
 id: JFK,
 miles: null,
},
}

예시 5: null 처리

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, miles:Integer>>
  • Output mode: null
json출력
nullnull

예시 6: null 처리

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, miles:Integer>>
  • Output mode: WITH_ERRORS
json출력
null{
 error: JSON input is null or empty,
 ok: null,
}

예시 7: null 처리

입력 JSON에서 요청한 필드가 null이면 결과 필드도 null입니다.

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, miles:Integer>>
  • Output mode: null
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": "JFK",
  "miles": null
 }
}
{
 airline: XB-112,
 airport: {
 id: JFK,
 miles: null,
},
}

예시 8: null 처리

구조체 필드가 배열인 경우입니다.

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, countries:Array<String>>>
  • Output mode: null
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": "JFK",
  "countries": ["USA", "Canada"]
 }
}
{
 airline: XB-112,
 airport: {
 countries: [ USA, Canada ],
 id: JFK,
},
}

예시 9: null 처리

구조체 필드가 빈 문자열인 경우입니다.

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, countries:Array<String>>>
  • Output mode: null
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": "",
  "countries": ["USA", "Canada"]
 }
}
{
 airline: XB-112,
 airport: {
 countries: [ USA, Canada ],
 id: empty string,
},
}

예시 10: null 처리

구조체 필드가 null 원소를 가진 배열인 경우입니다.

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, countries:Array<String>>>
  • Output mode: null
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": "JFK",
  "countries": ["USA", null]
 }
}
{
 airline: XB-112,
 airport: {
 countries: [ USA, null ],
 id: JFK,
},
}

예시 11: null 처리

구조체 필드가 null 문자열인 경우입니다.

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, countries:Array<String>>>
  • Output mode: null
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": null,
  "countries": ["USA", "Canada"]
 }
}
{
 airline: XB-112,
 airport: {
 countries: [ USA, Canada ],
 id: null,
},
}

예시 12: null 처리

맵 필드 하나가 있는 구조체를 처리합니다.

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, countries:Map<String, Integer>>>
  • Output mode: null
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": "JFK",
  "countries": {"USA": 4}
 }
}
{
 airline: XB-112,
 airport: {
 countries: {
 USA -> 4,
},
 id: JFK,
},
}

예시 13: null 처리

Double 필드를 가진 구조체를 해석합니다.

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, miles:Double>>
  • Output mode: null
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": "JFK",
  "miles": 4.2
 }
}
{
 airline: XB-112,
 airport: {
 id: JFK,
 miles: 4.2,
},
}

예시 14: null 처리

정수를 Double로 해석하면 Double 값을 반환합니다.

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, miles:Double>>
  • Output mode: null
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": "JFK",
  "miles": 4
 }
}
{
 airline: XB-112,
 airport: {
 id: JFK,
 miles: 4.0,
},
}

예시 15: null 처리

맵의 값이 null이면 결과 구조체에도 null 값이 남습니다.

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, countries:Map<String, Integer>>>
  • Output mode: null
json출력
{
 "airline": "XB-112",
 "airport": {
  "id": "JFK",
  "countries": {"USA": null}
 }
}
{
 airline: XB-112,
 airport: {
 countries: {
 USA -> null,
},
 id: JFK,
},
}

예시 16: 경계 조건

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, miles:Integer>>
  • Output mode: WITH_ERRORS
json출력
invalid{
 error: The JSON content is invalid or malformed,
 ok: null,
}

예시 17: 경계 조건

인자 값:

  • JSON: json
  • Schema: Struct<boolVal:Boolean, byteVal:Byte, shortVal:Short, intVal:Integer, longVal:Long, doubleVal:Double, floatVal:Float, dateVal:Date, timestampVal:Timestamp, decimalVal:Decimal(9, 4), myMap:Map<String, Integer>, myArray:Array<Integer>>
  • Output mode: WITH_ERRORS
json출력
{
 "timestampVal": "This is a string."
}
{
 error: The JSON content does not match the expected type,
 ok: null,
}
{"boolVal": 5}
{
 error: The JSON content does not match the expected type,
 ok: null,
}
{"byteVal": "This is not a byte."}
{
 error: The JSON content does not match the expected type,
 ok: null,
}
{"shortVal": "This is not a short."}
{
 error: The JSON content does not match the expected type,
 ok: null,
}
{"longVal": "This is not a long."}
{
 error: The JSON content does not match the expected type,
 ok: null,
}
{"intVal": 5.2}
{
 error: The JSON content does not match the expected type,
 ok: null,
}
{"doubleVal": "This is not a double."}
{
 error: The JSON content does not match the expected type,
 ok: null,
}
{"floatVal": "This is not a float."}
{
 error: The JSON content does not match the expected type,
 ok: null,
}
{"dateVal": "32/13/2020"}
{
 error: The JSON content does not match the expected type,
 ok: null,
}
{"decimalVal": "This is not a decimal."}
{
 error: The JSON content does not match the expected type,
 ok: null,
}
{"myMap": {"a": "str"}}
{
 error: The JSON content does not match the expected type,
 ok: null,
}
{"myArray": ["a", "b"]}
{
 error: The JSON content does not match the expected type,
 ok: null,
}

예시 18: 경계 조건

인자 값:

  • JSON: json
  • Schema: Struct<airport:Struct<id:String, miles:Integer>, boolVal:Boolean>
  • Output mode: WITH_ERRORS
json출력
{
 "boolVal": true
}
{
 error: null,
 ok: {
 airport: null,
 boolVal: true,
},
}
{
 "boolVal": "This is a string."
}
{
 error: The JSON content does not match the expected type,
 ok: null,
}

예시 19: 경계 조건

인자 값:

  • JSON: json
  • Schema: Struct<airline:String, airport:Struct<id:String, miles:Integer>>
  • Output mode: WITH_ERRORS
json출력
{
 "arrival_time":
{
 error: There was an unexpected EOF while parsing the JSON,
 ok: null,
}