Rでjson配列を操作するのは初めてです。以下のコードを使用してRパッケージjsonliteを.jsonファイルに書き込むと、 json配列全体がそのファイルの最初の行に表示されます(regはdata.frameです)。r - jsonlite json配列 "親要素"の末尾にキャリッジリターンを追加
rownames(reg) <- NULL
write(toJSON(reg), file = "test.json")
私は、ネストされた階層内の各メジャー(「親」)要素の末尾に「N \」キャリッジリターンを追加できるようにしたいと思いますので、その代わりに、以下のようになります。
[{"val":"ID1","prop":{"Sub":{"val":"foo"}},
{"val":"ID2","prop":{"Sub":{"val":"bar"}}]
の代わり:
[{"val":"ID1","prop":{"Sub":{"val":"foo"}},{"val":"ID2","prop":{"Sub":{"val":"bar"}}]
誰も私を助けることができますか?
注:私は「かわいい」レイアウトを望んでいません。私は親要素/すべての子プロパティごとに1つの行が必要です。
は、ここで私はstream_out
が動作するはずだと思うの例新しい行の要件を1としてdata.frame
reg <- data.frame(value=c("ID1", "ID2", "ID3"), properties.Subject.value=c("http://example.org/ID1", "http://example.org/ID2", "http://example.org/ID3"), properties.Subject.properties.value=c("http://example.org/xID1", "http://example.org/xID2", "http://example.org/xID3"))
value properties.Subject.value properties.Subject.properties.value ID1 http://example.org/ID1 http://example.org/xID1 ID2 http://example.org/ID2 http://example.org/xID2 ID3 http://example.org/ID3 http://example.org/xID3
'?write'には、sep引数があります。あなたは 'sep =" \ n "'を追加しようとするかもしれませんが、動作するかどうかは分かりません。 – lmo
私はあなたの要件を見落としました、あなたはかなりのレイアウトを望んでいません。したがって、削除された答え。あなたはサンプルのデータフレームを追加できますか? – user5249203
追加されたデータフレームの例! – areyoujokingme