Returns a JSON representation of the object(s)
Questions tagged [to-json]
108 questions
2
votes
1 answer
I want to create a multi nested json from my pandas dataframe
I have a pandas data frame in the following format :-
EMPCODE|Indicator|CustNAME
1 CASA Raja
1 CASA lala
1 CASA dada
1 TL Nan
1 l Nan
1 p …

SURYA DEV LAROIA
- 23
- 3
2
votes
1 answer
Upload file to Local directory as well as MongoDB
I am having an issue in uploading the file to pc as well as DB at same time.
I am using two different Modules in my code
Multer: For uploading file from front-end to PC
CSV-to-JSON: For converting CSV File to json in order to store that file in…

Monkey D. Luffy
- 181
- 1
- 3
- 16
2
votes
1 answer
python - Convert pandas dataframe to json or dict and then back to df with non-unique columns
I need to send a dataframe from a backend to a frontend and so first need to convert it either to an object that is JSON serialisable or directly to JSON. The problem being that I have some dataframes that don't have unique cols. I've looked into…

Ludo
- 2,307
- 2
- 27
- 58
2
votes
1 answer
Undefined Method Error in ruby on rails, when trying to produce a nested json format using to_json?
This is the product model in my gems lib s4s models folder:
module S4s
module Models
class Product < ActiveRecord::Base
self.table_name = 'product'
has_many :images, foreign_key: :product_id, class_name:…

Mani Sankar
- 23
- 3
2
votes
1 answer
Slow to_json with oj gem in Rails 4.2
I upgraded my Rails app from Rails 3.2 to Rails 4.2. The to_json performance in my views is terrible. In my Rails 3.2 app I used multi_json and the Oj gem to get great performance. With Rails 4.2 I setup the oj gem this way:
gem 'oj', '~> 2.14', '>=…

fnllc
- 3,047
- 4
- 25
- 42
2
votes
2 answers
Postgres to-json converts a composite type into empty structure
in the following code example postgresql (9.4) is supposed to transform a local variable of a composite type into a json string. apparently postgresql handle a variable with null value different than a null-value cast to the same type.
in my…

RootOfProblem
- 357
- 1
- 3
- 11
2
votes
1 answer
Why is to_json returning null values?
I'm building a Sinatra-based API and I'm seeing some weird responses for my User model. Every response returns a collection full of null values. Other models return as expected.
irb(main):018:0> User
=> User(id: integer, email: string, username:…

Tyler Rash
- 1,165
- 1
- 8
- 19
1
vote
1 answer
Create Json File if Dataframe > Column > Criteria matches
I am struggling with the following:
Row1 Row2
A 10
B 10
C 10
D 11
F 12
I have a large data and want to create a json file if its meets Row2. (It's an Object dtype)
if df['Row2'] == '10':
df.to_json(filelocation)
else:
…

Rav86
- 65
- 6
1
vote
2 answers
How to convert a dataframe to nested json
I have this DataFrame:
df = pd.DataFrame({'Survey': "001_220816080015", 'BCD': "001_220816080015.bcd", 'Sections': "4700A1/305, 4700A1/312"})
All the dataframe fields are ASCII strings and is the output from a SQL query (pd.read_sql_query) so the…

Roy Jaques
- 99
- 1
- 7
1
vote
2 answers
How to convert dataframe column into list of lists json format?
My dataframe looks like below and I want to use sales column and convert it into json files for each month as a list of lists.
sales
dt
156
2022-01
192
2022-01
147
2022-02
192
2022-02
for date in date_range:
df.loc[df['dt']…

data_coder
- 97
- 8
1
vote
1 answer
pandas column to list for a json file
from a Dataframe, I want to have a JSON output file with one key having a list:
Expected output:
[
{
"model": "xx",
"id": 1,
"name": "xyz",
"categories": [1,2],
},
{
...
},
]
What I have:
[
{
"model": "xx",
…

Minseven
- 122
- 1
- 7
1
vote
1 answer
Format array of date_time in hash during hash to json conversion
so I have a class whose hash representation looks like this.
{"dateTime"=>[1484719381, 1484719381], "dateTime1"=>[1484719381, 1484719381]}
The dateTime here is is a unix formatted dateTime array.
I am trying to convert this hash to an equivalent of…

MaryamAdnan
- 13
- 4
1
vote
1 answer
Encoding Algebraic Data Types with Aeson in Haskell
I have the following ADT implementation:
data FeatureValue =
FvInt Int
| FvFloat Float
| FvText Text
| FvBool Bool
deriving Show
data ApiResponse =
Online [[Maybe FeatureValue]]
| Offline [[[Maybe FeatureValue]]]
deriving…

Jivan
- 21,522
- 15
- 80
- 131
1
vote
1 answer
DataFrame to JSON format, using column value as value
I want to output the format of JSON, which is like:
{"553588913747808256":"rumour","524949003834634240":"rumour","553221281181859841":"rumour","580322346508124160":"non-rumour","544307417677189121":"rumour"}
Here, I have a df_prediction_with_id…

Woden
- 1,054
- 2
- 13
- 26
1
vote
1 answer
Pandas dataframe to json with format {column1 name : [Values], column2 name: [values], Column3 name... }
I'm new in python and pandas. I'm trying to convert a pandas dataframe to a json with format:
{column1 name : [Values], column2 name: [values], Column3 name... }
I've trying using:
df.to_json(orient='columns')
with this option I get something…

Leonel Garcia
- 79
- 1
- 8