JMP 테이블을 JSON으로 내보내기@Craige_Hales의 훌륭한 답변을 JSON <=> JMP로 확장, JMP 테이블을 원래 테이블의 행 순서를 유지하는 JSON 파일로 변환하는 방법이 있습니까 (인간이 읽을 수 있도록)? JMP 17.2.0을 사용합니다.
콘텐츠 구성데이터 블렌딩 및 정리결과 공유 및 전달Re: JMP 테이블을 JSON으로 내보내기이 JMP 테이블은 어떤 형식으로 변경해야 합니까?

New Table("Untitled",
Add Rows(5),
Compress File When Saved(1),
New Column("name",
Character,
"Nominal",
Set Values({"KATIE", "LOUISE", "JANE", "JACLYN", "LILLIE"})
),
New Column("age",
Numeric,
"Ordinal",
Format("Fixed Dec", 5, 0),
Set Values([12, 12, 12, 12, 12])
),
New Column("sex",
Character(1),
"Nominal",
Set Values({"F", "F", "F", "F", "F"})
),
New Column("height",
Numeric,
"Continuous",
Format("Fixed Dec", 5, 0),
Set Values([59, 61, 55, 66, 52])
),
New Column("weight",
Numeric,
"Continuous",
Format("Fixed Dec", 5, 0),
Set Values([95, 123, 74, 145, 64])
)
)

[
{
"name" : "KATIE",
"age" : 12,
"sex" : "F",
"height" : 59,
"weight" : 95
},
{
"name" : "LOUISE",
"age" : 12,
"sex" : "F",
"height" : 61,
"weight" : 123
},
{
"name" : "JANE",
"age" : 12,
"sex" : "F",
"height" : 55,
"weight" : 74
},
{
"name" : "JACLYN",
"age" : 12,
"sex" : "F",
"height" : 66,
"weight" : 145
},
{
"name" : "LILLIE",
"age" : 12,
"sex" : "F",
"height" : 52,
"weight" : 64
}
]
목록에 있는 항목의 순서에 따라 행 순서가 유지되지 않나요?
Re: JMP 테이블을 JSON으로 내보내기안녕하세요 @jthi 님 ,
답변 감사합니다. 더 자세히 설명했어야 했습니다. 연관 배열에서는 키 순서가 유지되지 않습니다. 예를 들어, 아래 스크립트에서는 성별 순서가 유지되지 않습니다.
이 결과는 완전히 새로운 해결책이 필요할 것 같습니다. 누군가가 그것을 알아낼 수 있을지 궁금합니다.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Sort( Replace Table, By( :sex ), Order( Descending ) );
result = [=> ];
For( i = 1, i <= N Rows( dt ), i += 1,
If( !Contains( result, dt:sex[i] ),
result[dt:sex[i]] = [=> ]
);
If( !Contains( result[dt:sex[i]], dt:age[i] ),
result[dt:sex[i]][dt:age[i]] = [=> ]
);
If( !Contains( result[dt:sex[i]][dt:age[i]], dt:name[i] ),
result[dt:sex[i]][dt:age[i]][dt:name[i]] = [=> ]
);
result[dt:sex[i]][dt:age[i]][dt:name[i]]["height"] = dt:height[i];
result[dt:sex[i]][dt:age[i]][dt:name[i]]["weight"] = dt:weight[i];
);
Write( As JSON Expr( result ) );
Re: JMP 테이블을 JSON으로 내보내기아직도 당신이 찾고 있는 형식이 무엇인지 확신할 수 없지만, 스크립트가 무엇을 생성하는지 볼 수 있습니다(제 기억이 맞다면 키가 문자열이 아니기 때문에 유효한 JSON이 아닙니다). 하지만 기본적으로 무언가를 기준으로 그룹화하고 싶습니다(이 경우 sex -> age -> name이 키이고 name은 더 많은 키가 있는 값을 가집니다). 결국 무엇을 하려고 합니까?
Re: JMP 테이블을 JSON으로 내보내기출력은 아래와 같아야 합니다. 단, "F"와 "M"의 순서가 반전되어야 합니다.
{
"F": {
12: {
"JACLYN": {
"height": 66,
"weight": 145
},
"JANE": {
"height": 55,
"weight": 74
},
"KATIE": {
"height": 59,
"weight": 95
},
"LILLIE": {
"height": 52,
"weight": 64
},
"LOUISE": {
"height": 61,
"weight": 123
}
},
13: {
"ALICE": {
"height": 61,
"weight": 107
},
"BARBARA": {
"height": 60,
"weight": 112
},
"SUSAN": {
"height": 56,
"weight": 67
}
},
14: {
"CAROL": {
"height": 63,
"weight": 84
},
"ELIZABETH": {
"height": 62,
"weight": 91
},
"JUDY": {
"height": 61,
"weight": 81
},
"LESLIE": {
"height": 65,
"weight": 142
},
"PATTY": {
"height": 62,
"weight": 85
}
},
15: {
"AMY": {
"height": 64,
"weight": 112
},
"MARY": {
"height": 62,
"weight": 92
}
},
16: {
"MARION": {
"height": 60,
"weight": 115
},
"MARTHA": {
"height": 65,
"weight": 112
}
},
17: {
"LINDA": {
"height": 62,
"weight": 116
}
}
},
"M": {
12: {
"JAMES": {
"height": 61,
"weight": 128
},
"ROBERT": {
"height": 51,
"weight": 79
},
"TIM": {
"height": 60,
"weight": 84
}
},
13: {
"DAVID": {
"height": 59,
"weight": 79
},
"JOE": {
"height": 63,
"weight": 105
},
"JOHN": {
"height": 65,
"weight": 98
},
"MICHAEL": {
"height": 58,
"weight": 95
}
},
14: {
"ALFRED": {
"height": 64,
"weight": 99
},
"CHRIS": {
"height": 64,
"weight": 99
},
"EDWARD": {
"height": 68,
"weight": 112
},
"FREDERICK": {
"height": 63,
"weight": 93
},
"HENRY": {
"height": 65,
"weight": 119
},
"JEFFREY": {
"height": 69,
"weight": 113
},
"LEWIS": {
"height": 64,
"weight": 92
}
},
15: {
"CLAY": {
"height": 66,
"weight": 105
},
"DANNY": {
"height": 66,
"weight": 106
},
"MARK": {
"height": 62,
"weight": 104
},
"ROBERT": {
"height": 67,
"weight": 128
},
"WILLIAM": {
"height": 65,
"weight": 111
}
},
16: {
"PHILLIP": {
"height": 68,
"weight": 128
}
},
17: {
"KIRK": {
"height": 68,
"weight": 134
},
"LAWRENCE": {
"height": 70,
"weight": 172
}
}
}
}Re: JMP 테이블을 JSON으로 내보내기귀하의 예에서 이름도 순서가 바뀌었습니다. 가장 바깥쪽 레이어만 특정 순서를 유지해야 합니까?
JMP에서 JSON을 직접 생성하는 기존 방법은 그런 형식을 지원하지 않고 JMP에는 Python의 OrderedDict와 같은 것이 없으므로 키는 항상 정렬됩니다. JMP18이 있다면 Python 통합을 활용할 수 있습니다. 순수하게 JMP/JSL에서 문자열을 빌드하는 데 일부 부분에 의존했을 것이라고 생각합니다. JSL의 다른 옵션은 데이터에 추가 정보를 추가하여 순서를 강제하고 연관 배열을 빌드하고 거기에서 JSON 문자열을 빌드한 다음(아직 저장하지 않음) Substitute를 사용하여 해당 값을 원래 값으로 바꿀 수 있다는 것입니다.
편집: JSON 문자열을 생성한 다음 거기에서 스왑을 수행할 수도 있습니다. 다음은 대체를 사용한 매우 빠른 예입니다.
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << Sort(Replace Table, By(:sex), Order(Descending));
replacements = ["F" => "$002$", "M" => "$001$"];
:sex << Set Each Value(replacements[:sex]);
result = [=> ];
For(i = 1, i <= N Rows(dt), i += 1,
If(!Contains(result, dt:sex[i]),
result[dt:sex[i]] = [=> ]
);
If(!Contains(result[dt:sex[i]], dt:age[i]),
result[dt:sex[i]][dt:age[i]] = [=> ]
);
If(!Contains(result[dt:sex[i]][dt:age[i]], dt:name[i]),
result[dt:sex[i]][dt:age[i]][dt:name[i]] = [=> ]
);
result[dt:sex[i]][dt:age[i]][dt:name[i]]["height"] = dt:height[i];
result[dt:sex[i]][dt:age[i]][dt:name[i]]["weight"] = dt:weight[i];
);
json_str = Substitute(As JSON Expr(result), replacements << get values, replacements << get keys);
Write(json_str);
이를 보다 견고하고 동적으로 만들기 위해서는 상당한 변경이 필요합니다(대체 키를 생성하는 기능, 원본 데이터 조작을 피하기 위한 하위 집합 사용/이를 위한 열 속성 활용)
Re: JMP 테이블을 JSON으로 내보내기저는 얼마 전 JMP to JSON 스크립트를 작업했습니다. 현재 반복 작업은 다음과 같습니다. 알파벳 키 순서 없이 JSON 파일을 정렬하는 경우(값 순서 속성에 기반?) "As JSON Expr()" 함수에 의존하기보다는 점진적인 단계로 JSON 표현식을 작성하는 것이 더 복잡할 것입니다.
또한, 아직 이것을 데이터 테이블로 다시 변환하기 위한 JSON to JMP 스크립트를 작성하지 않았습니다. 여기서 사용한 스키마는 제가 직접 만든 스키마입니다.
Names Default To Here( 1 );
dt = Current Data Table();
aa = Associative Array();
aa["name"] = dt << Get Name( "Ignore Extension" );
// get table variables
tvarnames = dt << get table variable names;
If( N Items( tvarnames ),
aa["table variables"] = Associative Array();
For Each( {tvar, i}, tvarnames,
Insert Into( aa["table variables"], tvar, dt << get table variable( tvar ) )
);
);
// get table scripts
tscriptnames = dt << get table script names;
If( N Items( tscriptnames ),
aa["table scripts"] = Associative Array();
For Each( {tscript, i}, tscriptnames,
// tscript = "DOE Dialog"
Insert Into( aa["table scripts"], tscript, Char( dt << get script( tscript ) ) )
);
);
// get script group names
script_groups = dt << get script groups names;
// iterate through each script group and get a list of the script in the group, add that to the associative array as a character string
If( N Items( script_groups ),
aa["script groups"] = Associative Array();
For Each( {scrgroup, i}, script_groups,
//scrgroup="FIT Y BY X"
Insert Into( aa["script groups"], scrgroup, Char( dt << get script group( scrgroup ) ) )
);
);
// capture row states
// captured as a string representation, because as json expr() doesn't handle associative array elements that are lists or matrices very well
aa["row states"] = Char( dt << get row states );
// get labeled columns
// note that the jmp data table stores these as a table property and not as a property for each column
aa["label columns"] = Char( dt << get label columns );
// get columns, column properties and data
aa["columns"] = Associative Array();
For( i = 1, i <= N Cols( dt ), i++,
col = Column( dt, i );
colname = col << get name;
// create column entry
aa["columns"][colname] = Associative Array();
// column order
aa["columns"][colname]["column order"]=i;
// modeling type
aa["columns"][colname]["modeling type"] = col << get modeling type;
// data type
aa["columns"][colname]["data type"] = col << get data type;
// format
aa["columns"][colname]["format"] = col << get format;
// get column properties
colproperties = col << get properties list;
If( N Items( colproperties ),
// note that << get properties list returns a list of expressions, converting them to character
For( k = 1, k <= N Items( colproperties ), k++,
colproperties[k] = Char( colproperties[k] )
);
//add properties element
aa["columns"][colname]["properties"] = Associative Array();
//add element for each property, capturing as character string to avoid expression eval issues
For Each( {prop, k}, colproperties, aa["columns"][colname]["properties"][prop] = Char( col << get property( prop ) ) );
);
// get data
aa["columns"][colname]["data"] = As List( col << get values );
);
Show( aa );
nw = New Window( "Complete Data Table as JSON", sb = Text Box( char(As JSON Expr( aa )), <<SET wrap="">" if you want to save a text file ; file(path || "jmpdt json.json", as json expr(aa), mode("replace")); * ode></SET>Re: JMP 테이블을 JSON으로 내보내기고맙습니다. 잘 작동하네요.